Posts

Showing posts with the label EXCEPTION HANDLING

EXCEPTION HANDLING

Exception Handling : Exception Handling allows programmers to make the program ready for any errors that may happen during execution and handle them gracefully so that it keeps running without errors. Types of Exceptions: 1) Built-in Types Exceptions 2) Standard Exceptions (e.g.  out_of_range ,  invalid_argument ,  runtime_error ) 3) Custom Exceptions try-catch Block : a) It is an exception handling mechanism when the code that may cause an exception is placed inside the try block and the code that handles the exception is placed inside the catch block. b) The " throw " keyword is used to throw the exception. c) The what() method present in every standard exception provides information about the exception. d) catch(...) creates a catch-all block which is executed when none of the catch statements are matched. catch by value : Catching exceptions by value creates a new copy of the thrown object in the catch block. catch by reference : Catch ...