Predict the output of following Java program class Main { public static void main(String args[]) { try { throw 10; } catch(int e) { System.out.println("Got… Read More
Tag Archives: Exception Handling
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… Read More
What happens in C++ when an exception is thrown and not caught anywhere like following program. #include <iostream> using namespace std; int fun() throw… Read More
Which of the following is true about exception handling in C++? 1) There is a standard exception class like Exception class in Java. 2) All… Read More
#include <iostream> using namespace std; class Test { static int count; int id; public: Test() { count++; id = count; cout << "Constructing object… Read More
#include <iostream> using namespace std; class Test { public: Test() { cout << "Constructing an object of Test " << endl; } ~Test() {… Read More
#include <iostream> using namespace std; int main() { try { try { throw 20; } catch (int n) { cout << "Inner Catch\n"; throw;… Read More
#include <iostream> using namespace std; int main() { try { throw 10; } catch (...) { cout << "default exception\n"; } catch (int param)… Read More
#include <iostream> using namespace std; int main() { try { throw 'a'; } catch (int param) { cout << "int exception\n"; } catch (...)… Read More
Output of following program #include<iostream> using namespace std; class Base {}; class Derived: public Base {}; int main() { Derived d; try { throw… Read More
What should be put in a try block? 1. Statements that might cause exceptions 2. Statements that should be skipped in case of an exception… Read More
What is the advantage of exception handling ? Remove error-handling code from the software’s main line of code. A method writer can choose to handle… Read More
#include <iostream> using namespace std; int main() { int x = -1; try { cout << "Inside try \n"; if (x < 0) { throw… Read More