Exceptions are errors that can only be handled using a \hyperlink{statements_try}{try catch block}. Any exception that is thrown in a \hyperlink{statements_try}{try block} will immediately cause execution of that thread to begin with the first statement of the \hyperlink{statements_try}{catch block}, regardless of the position of the program pointer of the running thread, even if nested function or object method calls have been made.

Exceptions can be thrown by the Qore system for a number of reasons, see the documentation for each function and object method for details.

Programmers can also throw exceptions explicitly by using the \hyperlink{statements_throw}{throw} and \hyperlink{statements_rethrow}{rethrow} statements.

Information about the exception, including the context in which the exception occurred, is saved in the exception hash, which can be retrieved by using a parameter variable in the \hyperlink{statements_try}{catch block}.

The exception hash is defined in the \hyperlink{struct_qore_1_1_exception_info}{Exception\+Info} \hyperlink{hashdecl}{hashdecl}.

System exceptions always throw at least 2 values, populating the {\ttfamily \char`\"{}err\char`\"{}} and {\ttfamily \char`\"{}desc\char`\"{}} keys of the exception hash, giving the exception string code and the exception description string, respectively, and occassionally, depending on the function, the {\ttfamily \char`\"{}arg\char`\"{}} key may be populated with supporting information. User exceptions have no restrictions, any values given in the \hyperlink{statements_throw}{throw statement} will be mapped to exception keys as per the table above.

See the \hyperlink{statements_on_exit}{on\+\_\+exit}, \hyperlink{statements_on_success}{on\+\_\+success} statement, and \hyperlink{statements_on_error}{on\+\_\+error} statement for statements that allow for exception-\/safe and exception-\/dependent cleanup in Qore code.

Classes that assist in exception-\/safe lock handling are the \hyperlink{class_qore_1_1_thread_1_1_auto_lock}{Auto\+Lock class}, the \hyperlink{class_qore_1_1_thread_1_1_auto_gate}{Auto\+Gate class}, the \hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock class}, and the \hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock class}. 