Thread: unexpected exception handler

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    unexpected exception handler

    Hello everyone,


    This question is about when it is allowed to call throw to re-throw exception -- make the exception re-throw.

    I can only think of two situations,

    1. in catch block of an exception;
    2. in unexpected handler.

    For (2), in unexpected handler, since the input parameter is null, so in order to get the exception information, we need to re-throw it and catch it to get exception informaiton.

    Is my understanding correct? Here is some pseudo code from Bjarne's book.

    Code:
    // suppose throwY is unexpcted handler
    void throwY() throw (Yunexpected)
    {
        try{
            throw; // have to re-throw and catch in order to get exception information since current input parameter is null and has no exception information, my understanding correct?
        } catch (Network_exception& p)
        {
            throw (Yunexpected (&p));
        } catch (...)
        {
            throw (Yunexpected (0));
        }
    }

    thanks in advance,
    George

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    since current input parameter is null
    There is no input parameter. Other than that, your understanding is correct.

    Note regarding both situations, however, that you may be arbitrarily far away from these positions, if you started there. I.e. you can call functions from within a catch block and rethrow there.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks for your clarification, CornedBee!


    My question is answered.

    Quote Originally Posted by CornedBee View Post
    There is no input parameter. Other than that, your understanding is correct.

    Note regarding both situations, however, that you may be arbitrarily far away from these positions, if you started there. I.e. you can call functions from within a catch block and rethrow there.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Exception handling in a large project
    By EVOEx in forum C++ Programming
    Replies: 7
    Last Post: 01-25-2009, 07:33 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Signal and exception handling
    By nts in forum C++ Programming
    Replies: 23
    Last Post: 11-15-2007, 02:36 PM
  4. Developing Custom Exception Handler :: C++
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 02-20-2002, 04:21 PM
  5. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM