N NezamDocumentation

Error Handling grammar#

Error handling grammar describes try, catch, finally, throw, raise, recover, and attempt flows for declared operational failures.

Source#

PropertyValue
Grammar filepackages/business/language/grammar/errorHandling.g4
Grammar nameerrorHandling
Grammar kindparser
Importscommon, expression, literal, type
Imported byfunction
Direct rule or token count5

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#

antlr
errorHandlingDeclaration: errorTryStatement
                        | raiseStatement
                        ;

errorTryStatement#

antlr
errorTryStatement: TRY blockStatement errorCatchClause* errorFinallyClause?;

errorCatchClause#

antlr
errorCatchClause: CATCH OPEN_PAREN errorCatchParameter? CLOSE_PAREN blockStatement;

Complete rule and token inventory#

text
errorCatchClause, errorCatchParameter, errorFinallyClause, errorHandlingDeclaration, errorTryStatement

Examples#

Try catch#

bl
try {
  post_invoice(invoice_id);
} catch (error: MissingApprovalPolicy) {
  raise error;
}

Finally block#

bl
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.
  • /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.
Source: packages/business/language/grammar-files/error-handling.md