Throwing and Catching Exceptions - C++ Statement

C++ examples for Statement:try catch

Description

Throwing and Catching Exceptions

Demo Code

#include <iostream> 
#include <string> 

using namespace std; 

void ProcessData(){ 
    throw new string("Oops, I found some bad data!"); 
} 

int main() { /*from ww  w  . j  av a 2 s.com*/
    try 
    { 
        ProcessData(); 
        cout << "No problems!" << endl; 
    } 
    catch (string *excep) 
    { 
        cout << "Found an error. Here's the message."; 
        cout << endl; 
        cout << *excep; 
        cout << endl; 
    } 
    cout << "All finished." << endl; 

    return 0; 
}

Result


Related Tutorials