• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C++ Exception Handling

Question 11

What happens in C++ when an exception is thrown and not caught anywhere like following program. C
#include <iostream>
using namespace std;

int fun() throw (int)
{
    throw 10;
}

int main() {

  fun();

  return 0;
}
 
  • Compiler error
  • Abnormal program termination
  • Program doesn\'t print anything and terminates normally
  • None of the above

Question 12

What happens when a function throws an error but doesn\'t specify it in the list of exceptions it can throw. For example, what is the output of following program? CPP
#include <iostream>
using namespace std;

// Ideally it should have been \"int fun() (int)\"
int fun()
{
    throw 10;
}

int main()
{
    try
    {
        fun();
    }
    catch (int )
    {
        cout << \"Caught\";
    }
    return 0;
}
  • Compiler Error
  • No compiler Error. Output is "Caught"

There are 12 questions to complete.

Last Updated :
Take a part in the ongoing discussion