Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void func(int a, int b)
{
    if(b < 1){
    	throw b;
    }
    else{
    	cout<<"Product of "<<a<<" and  "<<b<<" is: "<<a*b<<endl;
    }
}
 
int main()
{
    try
    {
    	try
            {			
        	    func(5,-1);
	    }
	   catch(int b)
            {
		if(b==0)
			throw "value of b is zero\n";
		else
			throw "value of b is less than zero\n";
	}
    }
    catch(const char* e)
    {
	cout<<e;
    }
}

A. value of b is zero

B. value of b is less than zero

C. Product of 5 and -1 is: -5

D. Aborted(core dumped)

Answer: Option B


Join The Discussion

Related Questions on Exception Handling in C plus plus

What is exception handling in C++?

A. A method to handle errors during runtime

B. A method to handle errors during compile time

C. A method to handle errors during linking

D. A method to handle errors during execution