throw()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samant.Trupti@gmail.com

    throw()

    Hi,

    bool CControlDrvInst ance::IsRebootR equired() 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
  • Roland Mueller

    #2
    Re: throw()

    On Apr 29, 3:32 pm, "Samant.Tru...@ gmail.com"
    <Samant.Tru...@ gmail.comwrote:
    Hi,
    >
    bool CControlDrvInst ance::IsRebootR equired() 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

    Comment

    • Samant.Trupti@gmail.com

      #3
      Re: throw()

      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.comwrote:
      Hi,
      >
       bool CControlDrvInst ance::IsRebootR equired() 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

      Comment

      • Nick Keighley

        #4
        Re: throw()

        On 29 Apr, 14:25, "Samant.Tru...@ gmail.com" <Samant.Tru...@ gmail.com>
        wrote:
        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.comwrote:
         bool CControlDrvInst ance::IsRebootR equired() 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 CControlDrvInst ance::IsRebootR equired() const throw()
        {
        try {
        if (subDevice1.IsR ebootRequired() ||
        subDevice1.IsRe bootRequired())
        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 CControlDrvInst ance::IsRebootR equired() const throw()
        {
        return true;
        }



        void my_code (CControlDrvIns tance& cdi)
        {
        if (cdi.IsRebootRe quired())
        cdi.Boot();
        }

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


        --
        Nick Keighley







        Comment

        • Richard Herring

          #5
          Re: throw()

          In message
          <86ed9a26-12dc-4217-8d15-daffa664a9eb@u1 2g2000prd.googl egroups.com>,
          "Samant.Trupti@ gmail.com" <Samant.Trupti@ gmail.comwrites
          >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.comwrote :
          Hi,
          >>
           bool CControlDrvInst ance::IsRebootR equired() 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

          Comment

          Working...