throw()

Discussion in 'C++' started by Samant.Trupti@gmail.com, Apr 29, 2008.

  1. Guest

    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
     
    , Apr 29, 2008
    #1
    1. Advertising

  2. On Apr 29, 3:32 pm, ""
    <> 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
     
    Roland Mueller, Apr 29, 2008
    #2
    1. Advertising

  3. Guest

    On Apr 29, 5:49 pm, Roland Mueller <>
    wrote:
    > On Apr 29, 3:32 pm, ""
    >
    > <> 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- 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
     
    , Apr 29, 2008
    #3
  4. On 29 Apr, 14:25, "" <>
    wrote:
    > On Apr 29, 5:49 pm, Roland Mueller <>
    > wrote:
    > > On Apr 29, 3:32 pm, ""
    > > <> wrote:


    > > >  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?


    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
     
    Nick Keighley, Apr 29, 2008
    #4
  5. In message
    <>,
    "" <> writes
    >On Apr 29, 5:49 pm, Roland Mueller <>
    >wrote:
    >> On Apr 29, 3:32 pm, ""
    >>
    >> <> 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
     
    Richard Herring, Apr 29, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    835
  2. Kerri
    Replies:
    2
    Views:
    13,044
    Kevin Spencer
    Oct 27, 2003
  3. PrashanthNagaraj
    Replies:
    2
    Views:
    1,755
    Guest
    Nov 24, 2003
  4. Replies:
    15
    Views:
    7,579
    Roedy Green
    Sep 8, 2005
  5. Emanuele D'Arrigo

    To throw or to throw not?

    Emanuele D'Arrigo, Nov 14, 2008, in forum: Python
    Replies:
    6
    Views:
    324
    Emanuele D'Arrigo
    Nov 15, 2008
Loading...

Share This Page