Defined in header <cparse/Parser.hh>
protected:
void exit( int status );
Throws a private Exited exception that is caught inside parse() Phase 5. Signals that the grammar has reached an unrecoverable state — parsing cannot continue in a way that would produce meaningful diagnostics.
Always call recordError() first to record what went wrong; exit() itself does not add any diagnostic.
Parameters
| Parameter | Description |
|---|---|
status | An integer status code stored in the Exited exception. Currently unused by parse() — the mere fact that the exception was thrown is what matters. Reserved for future extension. |
Return value
Does not return. Throws unconditionally.
Exceptions
Throws a private Parser::Exited exception. Not any standard exception type — callers cannot catch it externally. parse() catches it in Phase 5 and translates it to a false return with the return-point stack cleared.
Notes
The distinction between "return false from start()" and "call exit() from within a helper" is subtle and worth internalising:
- Return
falsefromstart()— clean control flow.parse()appends anInternal-kind"unexpected file parsing result"diagnostic on top of whatever the grammar itself recorded. - Call
exit()— bypasses whatever call stack was in progress. No automatic"unexpected file parsing result"diagnostic is appended. Use when the grammar has recorded a precise diagnostic and does not want boilerplate on top.
Because exit() unwinds the stack via C++ exception, any RAII guards, std::lock_guards, or destructors between the call site and parse() will run. If your grammar owns resources across the call, this is the correct behaviour; if you accidentally hold a lock that must not be released mid-parse, exit() is the wrong mechanism — return false from start() after unwinding manually.
Example
bool parseHeader()
{
if (!extractToken("VERSION"))
{
recordError(ParseError::Kind::Faulty,
"file lacks required VERSION header — cannot proceed");
exit(1); // unrecoverable — no other section makes sense without version
}
// ... read version number ...
return true;
}
See also
- Parser::parse — catches the
Exitedexception in Phase 5. - Parser::recordError — call before
exit(). - Parser::start — compares the two failure paths.

