Exception Handling

  • Uploaded by: Anik
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Exception Handling as PDF for free.

More details

  • Words: 253
  • Pages: 5
Exception Handling

What is exception handling • Exception handling provides a mechanism to decouple handling of errors or other exceptional circumstances from the typical control flow of your code. • This allows more freedom to handle errors when and however is most useful for a given situation, alleviating many (if not all) of the messiness that return codes cause.

Basic exception handling Ru • Exceptions in C++ are implemented using three keywords that work in conjunction with each other: throw, try, and catch. • When an exception is raised (using throw), execution of the program immediately jumps to the nearest enclosing try block (propagating up the stack if necessary). • If any of the catch handlers attached to the try block handle that type of exception, that handler is executed and

Looking for exceptions • In C++, we use the try keyword to define a block of statements (called a try block). The try block acts as an observer, looking for any exceptions that are thrown by statements within the try block.    • try   {        // Statements that may throw exceptio ns you want  to handle now go here        throw -1;    }  

Handling exceptions • Actually handling exceptions is the job of the catch block(s). The catch keyword is used to define a block of code (called a catch block) that handles exceptions for a single data type. • catch (int)    • {     // Handle an exception of type int he re     cout << "We caught an exception of  type int" << endl;   

Related Documents

Exception Handling
November 2019 33
Exception Handling
November 2019 36
Exception Handling
June 2020 26
Exception Handling
June 2020 22

More Documents from ""