Starter Tutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Home » Programming » C++ Programming » Programs » Exception Handling » CPP program to rethrow an exception
Suryateja Pericherla Categories: Exception Handling. 1 Comment on CPP program to rethrow an exception
Join Our Newsletter - Tips, Contests and Other Updates
Email
Name

In this article we will learn to implement a CPP program to rethrow an exception. A C++ program is provided below to demonstrate rethrowing an exception.

 

Program is as follows:

#include <iostream>
using namespace std;
int main()
{
	try
	{
		int a, b;
		cout<<"Enter two integer values: ";
		cin>>a>>b;
		try
		{
			if(b == 0)
			{
				throw b;
			}
			else
			{
				cout<<(a/b);
			}
		}
		catch(...)
		{
			throw; //rethrowing the exception
		}
	}
	catch(int)
	{
		cout<<"Second value cannot be zero";
	}
	return 0;
}

 

Input and output for the above program are as follows:

Enter two integer values: 10 0
Second value cannot be zero

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

1 Comment

You can follow any responses to this entry through the RSS 2.0 feed.

i want to write code well hlep me pls?????

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
Pinterest
Youtube
Instagram
Blogarama - Blog Directory