Sponsered Links
Categories
Sponsered Links

C++ Exception throwing example

 

This is a simple throwing an exception from a function called from within a try block.

#include <iostream> 

void fun(int test)
  cout << "Inside fun, test is: " << test << "\n"
  if(test
     throw test; 

 
int main()
  cout << "start\n"
 
  try {
    cout << "Inside try block\n"
    fun(0)
    fun(1)
    fun(2)
  
  catch (int i) {
    cout << "Caught an exception -- value is: "
    cout << i << "\n"
  
 
  cout << "end"
 
  return 0
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved