C C does not provide direct support to exception handling: it is the programmer's responsibility to prevent errors in the first place and test return values from the functions. In any case, a possible way to implement exception handling in standard C is to use setjmp/longjmp functions: #include <setjmp.h> #include <stdio.h> #include <stdlib.h> enum { SOME_EXCEPTION = 1 } exception; jmp_buf state; int main(void) { if (!setjmp(state)) // try { if (/* something happened */) { exception = SOME_EXCEPTION; longjmp(state, 0); // throw SOME_EXCEPTION } } else switch(exception) { case SOME_EXCEPTION: // catch SOME_EXCEPTION puts("SOME_EXCEPTION caught"); break; default: // catch ... puts("Some strange exception"); } return EXIT_SUCCESS; } Microsoft-specific Two types exist: Structured Exception Handling (SEH) Vectored Exception Handling (VEH, introduced in Windows XP) Example of SEH in C programming language: int filterExpression (EXCEPTION_POINTERS* ep) { ep->ContextRecord->Eip += 8; // divide instruction may be encoded from 2 to 8 bytes return EXCEPTION_CONTINUE_EXECUTION; } int main(void) { static int zero; __try { zero = 1/zero; __asm { nop nop nop nop nop nop nop } printf ("Past the exception.\n"); } __except (filterExpression (GetExceptionInformation())) { printf ("Handler called.\n"); } return 0; } C# A try block must have at least one catch or finally clause and at most one finally clause. public static void Main() { try { // Code that could throw an exception. } catch (HttpException ex) { // Handles a HttpException. The exception object is stored in "ex". } catch (Exception) { // Handles any CLR exception that is not a HttpException. // Since the exception has not been given an identifier, it cannot be referenced. } catch { // Handles anything that might be thrown, including non-CLR exceptions. } finally { // Always run when leaving the try block (including catch clauses), regardless of whether any exceptions were thrown or whether they were handled. // Often used to clean up and close resources such a file handles. // May not be run when Environment.FailFast() is called and in other system-wide exceptional conditions (e.g. power loss), or when the process crashes due to an exception in another thread. } } C++ #include <exception> int main() { try { // do something (might throw an exception) } catch (const std::exception& e) { // handle exception e } catch (...) { // catches all exceptions, not already caught by a catch block before // can be used to catch exception of