Exception handling syntax is the set of keywords and/or structures provided by a computer programming language to allow exception handling, which separates the handling of errors that arise during a program's operation from its ordinary processes. Syntax for exception handling 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. Catalogue of exception handling syntaxes Ada Exception declarations Some_Error : exception; Raising exceptions raise Some_Error; raise Some_Error with "Out of memory"; -- specific diagnostic message Exception handling and propagation with Ada.Exceptions, Ada.Text_IO; procedure Foo is Some_Error : exception; begin Do_Something_Interesting; exception -- Start of exception handlers when Constraint_Error => ... -- Handle constraint error when Storage_Error => -- Propagate Storage_Error as a different exception with a useful message raise Some_Error with "Out of memory"; when Error : others => -- Handle all others Ada.Text_IO.Put("Exception: "); Ada.Text_IO.Put_Line(Ada.Exceptions.Exception_Name(Error)); Ada.Text_IO.Put_Line(Ada.Exceptions.Exception_Message(Error)); end Foo; Assembly language 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. Bash #!/usr/bin/env bash #set -e provides another error mechanism print_error(){ echo "there was an error" } trap print_error exit #list signals to trap tempfile=`mktemp` trap "rm $tempfile" exit ./other.sh || echo warning: other failed echo oops) echo never printed One can set a trap for multiple errors, responding to any signal with syntax like: BASIC 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. ON ERROR GOTO handler OPEN "Somefile.txt" FOR INPUT AS #1 CLOSE #1 PRINT "File opened successfully" END handler: PRINT "File does not exist" END ' RESUME may be used instead which returns control to original position.