C++ Exception Handling Question

Introduction

Write a program that throws and catches an integer exception.

Handle the exception and print its value:

You can use the following code structure:

#include <iostream> 

int main() 
{ 
    //your code here
} 


#include <iostream> 

int main() 
{ 
    try 
    { 
         std::cout << "Throwing an integer exception with value of 123..."  
          << '\n'; 
        int x = 123; 
        throw x; 
    } 
    catch (int ex) 
    { 
         std::cout << "An integer exception of value: " << ex << " caught  
          and handled." << '\n'; 
    } 
} 



PreviousNext

Related