Introduction to Exception Handling in c++ try, catch and throw




This video tutorial introduces you to the concept of exception handling in c++ programming.
You are gonna learn what is exception handling, what is the use of try, catch and throw keywords, how to construct the try and catch block, how to throw an exception in detail with example.

source code for this tutorial

#include <iostream>
#include <stdexcept>

using namespace std;

int main()
{

    int a = 10, b= 0, c;

    try{
    if( b == 0 )
        throw "divide by zero error";
    c = a/b;

    cout << c << endl;
    }catch(const char *e){

    cout << "exception accured"<<endl<<e;

    }

    return 0;
}

 
Back To Top