Computer Science, asked by darshanaparida, 5 months ago

Find the output of the following C++ program.
#include <iostream>
#include <exception>
using namespace std;
struct ExceptionDemo: public exception
{
const char * function () const throw ()
{
return "Exception has occured";
}
int main(void)
{
try
{
throw ExceptionDemo();
}
catch(ExceptionDemo& a)
{
std::cout << a function() << std::endl;
}
catch(std::exception& b)
{
std::cout << "ExceptionDemo" << std::endl;
std::cout << "Exception Test" << std::endl;
}
}​

Answers

Answered by riyashroy
23

Answer:

community answers by others

Answered by ravilaccs
0

Answer:

The Output of the above program is C++ exception

Explanation:

Output:

HelloWorld.cpp:12:1: error: expected ‘(’ before ‘{’ token

{

^

HelloWorld.cpp:12:1: error: expected type-specifier before ‘{’ token

HelloWorld.cpp:11:32: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]

{ const char function () const throw

                               ^~~~~

HelloWorld.cpp:12:1: error: expected ‘)’ before ‘{’ token

{

^

HelloWorld.cpp: In member function ‘const char ExceptionDemo::function() const’:

HelloWorld.cpp:14:8: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]

return "Exception has occured"; }

       ^~~~~~~~~~~~~~~~~~~~~~~

HelloWorld.cpp: In function ‘int main()’:

HelloWorld.cpp:24:1: error: expected primary-expression before ‘catch’

catch(ExceptionDemos a)

^~~~~

HelloWorld.cpp:33:1: error: expected ‘catch’ at end of input

}

^

HelloWorld.cpp:33:1: error: expected ‘(’ at end of input

Similar questions