Exceptions_in_C__

Exceptions_in_C__ - ExceptionsinC+ Exceptions

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
    Exceptions in C++
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Exceptions Exceptions provide a way to handle the errors generated by our  programs by transferring control to functions called handlers. To catch exceptions we have to place our code on which we want  exception handling in the  try  block. If an exception occurs the control is  passed to the handler, otherwise the handlers are ignored. The code to be executed, that may produce exceptions, is placed in the  try  block and the error handlers are declared  with the keyword  catch .
Background image of page 2
    Example First Example #include <iostream> using namespace std; int main () { try { throw 10; } catch (int e) { cout << “We have a problem!!” << endl; } return 0; } Output : We have a problem!!!
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Throw The  throw  expression accepts one parameter as its argument and this is  passed to the exception handler. You can have a number of  throw   statements at different parts of your 
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Exceptions_in_C__ - ExceptionsinC+ Exceptions

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online