Advertisement
double d = 10.3;
try
{
throw (d); // Using a throw keyword to throw a variable of type double.
}
double d = 10.3;
try
{
throw d; // An exception of type int is caught by this catch block and the same type of exception is thrown.
}
catch(int i)
{
throw i; // An exception of type int is caught by this catch block and the same type of exception is thrown.
}
catch(int i)
{
throw; // An exception of type int is caught by this catch block and the same type of exception is thrown without mentioning it.
}
catch(int i)
{
double d = 10.2;
throw d; // An exception of type int is caught by this catch block but an exception of type double is thrown.
}
Advertisement
#include<iostream>
using namespace std;
int main()
{
char c = 'c';
try
{
throw(c); // "throw", explicitly throws an exception object of any type
}
catch(char c)
{
cout<<"Thrown Exception : char type ";
}
}
Thrown Exception : char type
#include<iostream>
using namespace std;
int main()
{
try
{
throw(1); //throws an exception of type int
}
catch(int i)
{
cout<<"Exception caught - int type \n";
cout<<"Caught exception is thrown again \n";
throw i; //throwning the caught exception of type int
}
}
Exception caught - int type
Caught exception is thrown again
terminate called after throwing an instance of 'int'
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement