0% found this document useful (0 votes)
24 views3 pages

222 +FAQ+ (Intro+Exception+Handling+Construct+)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

222 +FAQ+ (Intro+Exception+Handling+Construct+)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Are TRY,CATCH, THROW default names or can be replaced by any

name??

Those are key words.


You can’t change them.

is return and throw are same?


can return be written in place of throw?
there is no else in try function...why?
return is for returning result.
throw is for reporting an error.
if you change three roles then roles of try and catch will also change.

what if user enters a char or string the what should be written in


if statement?

you can have multiple catch for same try, another with different data type
can be used

use of cout instead of throw

If you use cout , user will know the error.


throw will inform the calling function about error.

Can you tell me what will happen if we throw a class and try to
display it in the catch() section , like
catch(MyException e)
{
cout << e << endl;
}
don’t display it directly. Call what function
cout<<e->what();
what() should return a string message.
why you have not throw object of class why you have throw
default constructor throwing constructor will create the object and
throw.

Can we throw functions too ? like when exception comes up we


want some certain operation to be done...

We can throw int , char or object of a class.

inheriting class 'exception'


why class 'Myexception' is inheriting from class 'exception' ?
and by which method it is inheriting?(publically,protectedly or
privately)

For user defines exception class we have to inherit from exception class.
You can inherit it in any way.
It is better to do it using public. Must write public there.

in case of an exception involving both base and derived class ,


why is it necessary to write catch statement for derived class first
and then the base class?

if we have base class named "Vehicle" and derived class "Car" for exceptions.
if an exception of class "Car" is thrown and the catch block is for "Vehicle" then
it will catch the exception of "Car" coz it is also a "Vehicle".

can u please help me in practice exercise 13


exercise is to define and throw, user-defined exceptions.
1. StackOverflor is inheriting from exception but it is dummy, so way of
inheritance has no importance. you can make it public also.
2. yes try and catch should be used for handling exception. I said, if you
want to handle then write try and catch,

You might also like