Error Handling grammar#
Error handling grammar describes try, catch, finally, throw, raise, recover, and attempt flows for declared operational failures.
Source#
| Property | Value |
|---|---|
| Grammar file | packages/business/language/grammar/errorHandling.g4 |
| Grammar name | errorHandling |
| Grammar kind | parser |
| Imports | common, expression, literal, type |
| Imported by | function |
| Direct rule or token count | 5 |
How to use this page#
Read the examples first when authoring Business Language. Use the rule inventory when checking exact grammar coverage or when updating parser, lowering, editor, or documentation behavior.
Entry rules and syntax families#
Start with these rules when reading this grammar: errorHandlingDeclaration, errorTryStatement, errorCatchClause, errorFinallyClause.
- Declarations:
errorHandlingDeclaration - Statements:
errorTryStatement - Clauses:
errorCatchClause,errorFinallyClause
Key grammar excerpts#
errorHandlingDeclaration#
errorHandlingDeclaration: errorTryStatement
| raiseStatement
;errorTryStatement#
errorTryStatement: TRY blockStatement errorCatchClause* errorFinallyClause?;errorCatchClause#
errorCatchClause: CATCH OPEN_PAREN errorCatchParameter? CLOSE_PAREN blockStatement;Complete rule and token inventory#
errorCatchClause, errorCatchParameter, errorFinallyClause, errorHandlingDeclaration, errorTryStatementExamples#
Try catch#
try {
post_invoice(invoice_id);
} catch (error: MissingApprovalPolicy) {
raise error;
}Finally block#
try {
lock_invoice(invoice_id);
post_invoice(invoice_id);
} finally {
unlock_invoice(invoice_id);
}Common authoring mistakes#
- Do not copy examples without checking the rule inventory for the exact grammar boundary.
- Do not add behavior that depends on missing configuration or undeclared user-facing errors.
Related guides#
- /language/messages-errors/
- /language/statements-control-flow/
Authoring notes#
- Keep examples aligned with the grammar source, not with inferred syntax from another language.
- Use declared messages for user-facing failures, and fail closed when required configuration is absent.