C++ Exception Question

Discussion in 'C Programming' started by qianz99@gmail.com, May 9, 2010.

  1. Guest

    If I don't try catching every possible block how can I catch all the
    exceptions?

    I read C++ FAQ
    [17.13] I have too many try blocks; what can I do about it

    However I am still a little bit confused about

    Why usually we throw a C++ exception?
    Is it because that we need to do certain clean up?

    Thanks
     
    , May 9, 2010
    #1
    1. Advertising

  2. Ian Collins Guest

    On 05/10/10 09:57 AM, wrote:
    > If I don't try catching every possible block how can I catch all the
    > exceptions?


    comp.lang.c++ is just down the hall on the right (or was that left?).

    --
    Ian Collins
     
    Ian Collins, May 10, 2010
    #2
    1. Advertising

  3. kathir cpp Guest

    On May 9, 2:57 pm, "" <> wrote:
    > If I don't try catching every possible block how can I catch all the
    > exceptions?
    >
    > I read C++ FAQ
    > [17.13] I have too many try blocks; what can I do about it
    >
    > However I am still a little bit confused about
    >
    > Why usually we throw a C++ exception?
    > Is it because that we need to do certain clean up?
    >
    > Thanks


    C++ exceptions are very useful in finding the errors at run time on
    what went wrong? With in the catch(...) block, we will a message into
    the log file displaying the function name and cause of error. If there
    is an run time exception happens, we can check the log file to see
    which function caused the error. This is an example of one usage.

    There are some cases where you must use exxceptions. For exxample, if
    you need to return a value from a constructor function, throwing an
    exception is the only way as constructor will not return any value.

    If you want to catch all the exceptions, then in your main() function
    use try catch.
     
    kathir cpp, May 11, 2010
    #3
  4. On 11 May, 11:00, kathir cpp <> wrote:
    > On May 9, 2:57 pm, "" <> wrote:
    >
    > > If I don't try catching every possible block how can I catch all the
    > > exceptions?

    >
    > > I read C++ FAQ
    > > [17.13] I have too many try blocks; what can I do about it

    >
    > > However I am still a little bit confused about

    >
    > > Why usually we throw a C++ exception?
    > > Is it because that we need to do certain clean up?

    >
    > > Thanks

    >
    > C++ exceptions are very useful in finding the errors at run time on
    > what went wrong? With in the catch(...) block, we will a message into
    > the log file displaying the function name and cause of error. If there
    > is an run time exception happens, we can check the log file to see
    > which function caused the error. This is an example of one usage.
    >
    > There are some cases where you must use exxceptions. For exxample, if
    > you need to return a value from a constructor function, throwing an
    > exception is the only way as constructor will not return any value.
    >
    > If you want to catch all the exceptions, then in your main() function
    > use try catch.


    PLEASE post this comp.lang.c++
    exceptions are a tricky business and need to be discussed by people
    who know what they are talking about
     
    Nick Keighley, May 11, 2010
    #4
    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. jeff
    Replies:
    0
    Views:
    1,536
  2. jeff
    Replies:
    3
    Views:
    1,691
    Scott
    Jun 26, 2003
  3. Kerri
    Replies:
    2
    Views:
    13,035
    Kevin Spencer
    Oct 27, 2003
  4. Ola
    Replies:
    0
    Views:
    535
  5. Selen
    Replies:
    0
    Views:
    2,688
    Selen
    May 28, 2004
Loading...

Share This Page