Question 1 of 25
Hints left: 3
Q1
What is Re-throwing an exception means in C++?
Q2
What are the different types of exceptions?
Q3
Which statement about exception handling in C++ is true?
Q4
What will be the output of the following C++ code? #include <iostream> #include <string> #include <cstdlib> using namespace std; class A { int a; public: A(){} }; class B: public A { int b; public: B(){} }; void func() { B b; throw b; } int main() { try{ func(); } catch(B b){ cout<<"Caught B Class\n"; } catch(A a){ cout<<"Caught A Class\n"; } }
Q5
Which keyword is used to throw an exception?
Q6
What will be the output of the following C++ code? #include <iostream> #include <string> #include <cstdlib> using namespace std; class A { int a; public: A(){} }; class B: public A { int b; public: B(){} }; void func1() { B b; throw b; } void func2() { A a; throw a; } int main() { try{ func1(); } catch(...){ cout<<"Caught All types of exceptions\n"; } try{ func2(); } catch(B b){ cout<<"Caught All types of exceptions\n"; } }
Q7
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 == 0){ throw "This value of b will make the product zero. " "So please provide positive values.\n"; } else{ cout<<"Product of "<<a<<" and "<<b<<" is: "<<a*b<<endl; } } int main() { try{ func(5,0); } catch(char* e){ cout<<e; } }
Q8
What will be the output of the following C++ code? #include <iostream> #include <string> #include <cstdlib> using namespace std; class A { int a; public: A(){} }; class B: public A { int b; public: B(){} }; void func() { B b; throw b; } int main() { try{ func(); } catch(B *b){ cout<<"Caught B Class\n"; } catch(A a){ cout<<"Caught A Class\n"; } }
Q9
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 == 0){ throw "This value of b will make the product zero. " "So please provide positive values.\n"; } else{ cout<<"Product of "<<a<<" and "<<b<<" is: "<<a*b<<endl; } } int main() { try{ func(5,0); } catch(const char* e){ cout<<e; } }
Q10
Where should we place catch block of the derived class in a try-catch block?
Q11
What is an exception in C++ program?
Q12
How Exception handling is implemented in the C++ program?
Q13
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; } }
Q14
What is the behavior of the 'std::terminate' function in C++?
Q15
Why do we need to handle exceptions?
Q16
Header file used for exception handling in C++?
Q17
Which keyword is used to specify that a function will throw any exceptions in C++?
Q18
What is an error in C++?
Q19
By default, what a program does when it detects an exception?
Q20
Which part of the try-catch block is always fully executed?
Q21
What id the syntax for catching any type of exceptions?
Q22
Uncaught exception leads to . . . . . . . .
Q23
What is the purpose of the 'std::exception_ptr::rethrow' function in C++?
Q24
What is the purpose of the 'std::unexpected' function in C++ exception handling?
Q25
An uncaught handler returns to . . . . . . . .