C++ Exception Question

Q

qianz99

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
 
I

Ian Collins

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?).
 
K

kathir cpp

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.
 
N

Nick Keighley

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?

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top