Exception handling syntax varies between programming languages, partly to cover semantic differences but largely to fit into each language's overall syntactic structure. Some languages do not call the relevant concept 'exception handling'; others may not have direct facilities for it, but can still provide means to implement it.
Most commonly, error handling uses a try...[catch...][finally...]
block, and errors are created via a throw
statement, but there is significant variation in naming and syntax.
Most assembly languages will have a macro instruction or an interrupt address available for the particular system to intercept events such as illegal op codes, program check, data errors, overflow, divide by zero, and other such. IBM and Univac mainframes had the STXIT macro. Digital Equipment Corporation RT11 systems had trap vectors for program errors, i/o interrupts, and such. DOS has certain interrupt addresses. Microsoft Windows has specific module calls to trap program errors.
One can set a trap for multiple errors, responding to any signal with syntax like:
An On Error goto/gosub structure is used in BASIC and is quite different from modern exception handling; in BASIC there is only one global handler whereas in modern exception handling, exception handlers are stacked.
The most common way to implement exception handling in standard C is to use setjmp/longjmp
functions:
Two types exist:
Example of SEH in C programming language:
In C++, a resource acquisition is initialization technique can be used to clean up resources in exceptional situations. C++ intentionally does not support finally
. The outer braces for the method are optional.
Adobe ColdFusion documentation
Adobe ColdFusion documentation
Added to the standard syntax above, CFML dialects of Railo and Lucee allow a retry
statement.