25 Nov 2019

  • November 25, 2019
  • Amitraj
Exception Handling Mechanism in C++

-> C++ exception handling mechanism is basically built upon 3 keywords namely  try, throw and catch.

-> The keyword try is used to preface a block of statements which may generate exceptions. This block of statement is known as try block.

-> When an exception is detected, it is thrown using throw statement int the try block.

-> A catch block defined by the keyword catch , catches the exception thrown by the throw statement int the try block and handles it appropriately.
          A catch block that catches an exception must immediately follow the try block that throws the exception.

  
Try Block
Detect and throw
An exception

   Exception Object

Catch Block
Catches and handles the exception






Related Posts:

  • Exception specification in C++ Exception specification -> Older code may contain dynamic exception specifications. They are now deprecated in C++, but still supported. A dynamic exception specification follows the declaration of a function, appending … Read More
  • Static Class member in Class Template Static Class member in Class Template -> Each instantiation of class template has its own copy of member static variables. For example, in the following program there are two instances collection and collection. So … Read More
  • Advantages / Benefits of Exception Handling Advantages of Exception Handling -> Following are the advantages of exception handling: 1. Exception handling separates the exception handling code from the main logic of program. 2. Exceptions can be handled outside … Read More
  • Overloading function Templates in C++ Overloading function Templates in C++ -> We may overload a function Template either by a non - template function template. -> if we call the name of an overloaded function template, the compiler will try to deduce it… Read More
  • Templates in C++ Templates in C++ -> Templates is one of the features added to C++ Recently. it is a new concept which enable us to define Generic classes and functions and thus provides support for Generic programming. -> Generic pr… Read More

Translate

Popular Posts