Re: Exception Handling
On Jun 6, 11:17 pm, Speed <lostandha...@gmail.com> wrote:
So for example if I write this code, my program crashes.
Not really suprpising, since you get SIGFPE (arithmetics[1] error
signal) on a Un*x box or alike. Genrally, such kind of run-time erros
are not converted to C++ exceptions (unless you are using MSVC, where
you _can_ catch it with `catch(...)').
So I am
guessing I need to 'throw' something? So in a bigger bunch of code,
how do I know what to throw?
You should check the denominator prior to performing division. You
might get out with an assert(), or decide to throw an instance of
std::logic_error[2] if the value comes from your program logic.
Otherwise, if the value comes from user input it will be appropriate
to throw std::runtime_error[3].
--
Regards,
Alex Shulgin
--
[1] SIGFPE stands for 'Floating point error' signal.
[2],[3] or an instance of your exception class derived from that.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]