throw()

  • Follow


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
0
Reply Samant.Trupti (36) 4/29/2008 12:32:13 PM

On Apr 29, 3:32 pm, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.com> wrote:
> 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

> If I have this in my code do I need to include "try catch" block?  If
> yes why?
>
> Thanks
> TS

0
Reply roland.em0001 (4) 4/29/2008 12:49:21 PM


On Apr 29, 5:49=A0pm, Roland Mueller <roland.em0...@googlemail.com>
wrote:
> On Apr 29, 3:32 pm, "Samant.Tru...@gmail.com"
>
> <Samant.Tru...@gmail.com> wrote:
> > Hi,
>
> > =A0bool CControlDrvInstance::IsRebootRequired() const throw()
> > In this code what is throw() do? =A0I 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
>
>
>
> > If I have this in my code do I need to include "try catch" block? =A0If
> > yes why?
>
> > Thanks
> > TS- Hide quoted text -
>
> - 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
0
Reply Samant.Trupti (36) 4/29/2008 1:25:32 PM

On 29 Apr, 14:25, "Samant.Tru...@gmail.com" <Samant.Tru...@gmail.com>
wrote:
> On Apr 29, 5:49=A0pm, Roland Mueller <roland.em0...@googlemail.com>
> wrote:
> > On Apr 29, 3:32 pm, "Samant.Tru...@gmail.com"
> > <Samant.Tru...@gmail.com> wrote:

> > > =A0bool CControlDrvInstance::IsRebootRequired() const throw()
> > > In this code what is throw() do? =A0I 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.
> >
> > > If I have this in my code do I need to include "try catch" block? =A0I=
f
> > > yes why?
>
> Ohhh ok. =A0So 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.


--
Nick Keighley







0
Reply nick_keighley_nospam (4574) 4/29/2008 2:00:29 PM

In message 
<86ed9a26-12dc-4217-8d15-daffa664a9eb@u12g2000prd.googlegroups.com>, 
"Samant.Trupti@gmail.com" <Samant.Trupti@gmail.com> writes
>On Apr 29, 5:49�pm, Roland Mueller <roland.em0...@googlemail.com>
>wrote:
>> On Apr 29, 3:32 pm, "Samant.Tru...@gmail.com"
>>
>> <Samant.Tru...@gmail.com> wrote:
>> > 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.
>>
>>
>> > If I have this in my code do I need to include "try catch" block? �If
>> > yes why?
>>
>
>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.

-- 
Richard Herring
0
Reply Richard 4/29/2008 2:25:47 PM

4 Replies
21 Views

(page loaded in 0.083 seconds)


Reply: