Category Archives: Exception Handling

C++: Exception Handling Part 3

1. Explain Exception Handling.

2. Explain about specifying rethrowing exception.

3. Example showing the use of specifying rethrowing exception in C++.


/*
Developed By: Prof. Vinod Pillai
vinodthebest@gmail.com
Exception Handling-Part 3.
*/

#include

using namespace std;

void testException1() throw(int,char)
{
int val;

cout<>val;

if(val<=0)
{
throw(100);

//throw(‘a’);

//throw(10.56);
}
}

void testException2() throw()
{
int val;

cout<>val;

if(val<=0)
{
throw(100);
}
}

int main()
{
try
{
testException1();

//testException2();
}
catch(int value)
{
cout<<“\n——-Rethrow Integer Exception occured——-“;
}
catch(char value)
{
cout<<“\n——-Rethrow Character Exception occured——-“;
}
catch(…)
{
cout<<“\n——-Rethrow All Exception occured——-“;
}
return 0;
}

Advertisements

1 Comment

Filed under C++, Exception Handling

C++ : Exception Handling Part 2

1. Explain Exception Handling.

2. Explain multiple catch blocks.

3. Explain re-throwing exception.

4. Explain catch all exception that is catch(…).

5. Example showing the use of multiple catch and re-throwing exception in C++.


/*
Developed By: Prof. Vinod Pillai
vinodthebest@gmail.com
Exception Handling-Part 2.
*/

#include

using namespace std;

void testException1()
{
try
{
//throw(100);

//throw(‘a’);

//throw(10.56);
}
catch(int val)
{
cout<<“\n——-Integer Exception occured——-“;
}
catch(char val)
{
cout<<“\n——-Character Exception occured——-“;
}
catch(…)
{
cout<<“\n——-All Exceptions handling——-“;
}
}

void testException2()
{
int val;

cout<>val;

if(val<=0)
{
throw(val);
}
}

int main()
{
testException1();

try
{
testException2();
}
catch(int value)
{
cout<<“\n——-Rethrow Exception occured——-“;
}
return 0;
}

Leave a comment

Filed under C++, Exception Handling

C++ : Exception Handling Part 1

1. Explain Exception Handling & its use.

2. Explain the [try,catch & throw]

3. Example showing the use of Exception handling.


/*
Developed By: Prof. Vinod Pillai
vinodthebest@gmail.com
Exception Handling-Part 1.
*/

#include

using namespace std;

void testException()
{
int rel;

cout<>rel;

try
{
if(rel<=0)
{
throw(rel);
}
else
{
cout<<“\nThe value is:”<<rel;
}
}
catch(int val)
{
cout<<“\n——-Exception occured——-“;
}
}

int main()
{
testException();

return 0;
}

Leave a comment

Filed under C++, Exception Handling