Jump to content

C++ Language/ErrorHandling/CppExceptionHandling

From Wikibooks, open books for an open world

If some exceptionally problematic situation might occur in code (either your code or library functions that you call), enclose that code within try {your code} catch (...) {handler}. When your problem occurs, your code "throws an exception" by doing throw 99;, and program flow will jump to the handler (even if that requires the C++ language to "unwind" a series of called functions). That data (99 in this example) is an explanation for what went wrong; it is typed so you could actually program a sequence of catch (int aiExplanation) {handler} with catch (...) meaning "all other types".

Additional information about C++ Exception Handling