throw()

S

Samant.Trupti

Hi,

bool CControlDrvInstance::IsRebootRequired() const throw()
In this code what is throw() do? I just have slight knowledge that is
a exception handler but how does it work.
If I have this in my code do I need to include "try catch" block? If
yes why?

Thanks
TS
 
R

Roland Mueller

Hi,

bool CControlDrvInstance::IsRebootRequired() const throw()
In this code what is throw() do? I just have slight knowledge that is
a exception handler but how does it work.

Empty throw() declares that the function is not expected to throw any
exceptions. If it nevertheless does, abort() is called and the
exception cannot be catched from client code using the function.

BR,
Roland
 
S

Samant.Trupti

Empty throw() declares that the function is not expected to throw any
exceptions. If it nevertheless does, abort() is called and the
exception cannot be catched from client code using the function.

BR,
Roland





- Show quoted text -

Ohhh ok. So it is like "on error resume next" in VB right?
Is that mean we cannot have "try catch" in that function?
Thanks
 
N

Nick Keighley

Ohhh ok.  So it is like "on error resume next" in VB right?

what is? I suppose a try-catch is. But the exception declaration
above (the throw() bit) isn't. The ED is saying this function
does not throw any exceptions.
Is that mean we cannot have "try catch" in that function?

IsBootRequired() can have a try-catch (though probably not a
good idea).

bool CControlDrvInstance::IsRebootRequired() const throw()
{
try {
if (subDevice1.IsRebootRequired() ||
subDevice1.IsRebootRequired())
return true;
else
return false;
}
catch (...)
{
//oops something threw!
return true; // just in case...
}
}

so it doesn't throw. More likely is it is just too simple to
throw. Or has been carefully proven not to throw.

bool CControlDrvInstance::IsRebootRequired() const throw()
{
return true;
}



void my_code (CControlDrvInstance& cdi)
{
if (cdi.IsRebootRequired())
cdi.Boot();
}

if neither of the function calls throw then my_code()
won't throw either.
 
R

Richard Herring

In message
Ohhh ok. So it is like "on error resume next" in VB right?
Wrong.

Is that mean we cannot have "try catch" in that function?

No. It may even mean that you _need_ a catch block:

It's a promise by the function to its caller, that nothing it does will
propagate an exception outside the function. In the body of the function
there may very well be a try-catch block, if it has to call other
functions that don't give that guarantee.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top