writing Functions that are gonna Throw Exceptions




This video tutorial explains how to make a function to throw set of exceptions in c++ exception handling.
You are going to learn how to declare functions to specify to the c++ that they are gonna throw exceptions, how to restrict a function from throwing any exception in detail with example.

source code for this tutorial

#include <iostream>
#include <stdexcept>

using namespace std;

void test() throw(int,char,runtime_error){

throw runtime_error("what the hack");

}

int main()
{
    try{
    test();
    }catch(int e){
    cout <<" integer type "<< e <<endl;
    }
    catch(char c){
    cout <<" character type "<< c <<endl;
    }
    catch(runtime_error r){
    cout <<" runtime error type "<< r.what() <<endl;
    }

    return 0;
}