Re: Divide by 0 - exception thrown?
- From: "Jason Doucette" <www.jasondoucette.com>
- Date: Tue, 17 Oct 2006 23:27:12 -0300
Um, did I miss something?
Only the fact that I am too easily distracted. (There are days like today
when I have OE open all day - sometimes I walk away from my desk in mid
post and forget where I was when I left. It is an age thing. <g>)
Hey, that's quite ok. I am sure this is a consequence of you posting very
often, which I am sure many people appreciate. I am one of them.
I feel I should say this, although off-topic: I've found that using
catch (...) is almost always a no-no. If you merely catch every
exception, sometimes you'll catch ones that are *really* bad, and you can
do nothing to save your application from crashing (maybe you can right
then, but not 2 ms later). The issue is so severe, that your program
will crash anyway. This means the effort is futile.
There is a enough to be said on the topic of exceptions for a book (or
twelve) by language experts of which I am not one.
Yes, the very lengthy Deep C++ series was an indication of this. As well as
the article you mentioned by your friend, Doug Harrison:
http://members.cox.net/doug_web/eh.htm
Doug's article is great. And it goes to further show that you really should
never use catch (...), especially if you don't have VC++ 2005. Now that I
think about it, when I was using catch (...) in the past (with VC++ 2003),
it WAS catching hardware exceptions (they are converted into structured
exceptions), when the OS should have produced a crash dump, instead. I
stopped using catch (...) for this main reason (among others), since it was
hiding needed information about what caused the crash. I realize now that
it shouldn't have caught these, and that this improper implementation of
catch (...) drained any idea I would have had that the two types of
exceptions were different...
On a personal level - and please don't try this at home <G> - in much of
what I write in C++ I tend to use return codes a lot and exceptions only
sparingly. On the .Net platform or with Java, exceptions feel more
natural. (That may have nothing to do with anything except the fact that I
grew up on assembly language, Fortran, Pascal and C where exceptions were
not available).
Same here. I also have the assembly and Pascal background. I started using
error codes because it seemed more logical due the lack of knowledge of
exceptions. But, today, I continue to use them because I enjoy having the
error checking code visible. It is hidden from view with exception
handling. But, I agree in some cases (such as reading in a complex file
format, or a function that makes many separate memory allocations) it is
very nice to have exception handling handle all errors all in one place, at
the end, rather than perform error checking / clean up code throughout the
entire function <sigh> sometimes making it twice as long. Indeed, this is
what people love about exception handling; it doesn't clog the code up with
error checking. It's just hard to get the best of both worlds...
Exactly right. If the application is not too badly hosed you can try to
create a mini-dump
http://windowssdk.msdn.microsoft.com/en-us/library/ms680369(VS.80).aspx
for post mortem analysis. There are good mini-dump samples here, too.
http://www.debuginfo.com/examples/effmdmpexamples.html
I don't have experience with minidumps, yet. I'll take a look at those.
Thanks.
On the other hand, if you catch these exception, and attempt to 'save'
the application from crashing, it will likely just crash anyway, and then
you're left with no information. You'll have no idea where the error
occurred...
That is the prevailing wisdom.
Great. Glad I am on track.
Thanks,
--
Jason Doucette / Xona.com
www.jasondoucette.com / www.xona.com
.
- References:
- Divide by 0 - exception thrown?
- From: Jason Doucette
- Re: Divide by 0 - exception thrown?
- From: David Wilkinson
- Re: Divide by 0 - exception thrown?
- From: Jason Doucette
- Re: Divide by 0 - exception thrown?
- From: William DePalo [MVP VC++]
- Re: Divide by 0 - exception thrown?
- From: Jason Doucette
- Re: Divide by 0 - exception thrown?
- From: William DePalo [MVP VC++]
- Re: Divide by 0 - exception thrown?
- From: Jason Doucette
- Re: Divide by 0 - exception thrown?
- From: William DePalo [MVP VC++]
- Re: Divide by 0 - exception thrown?
- From: Jason Doucette
- Re: Divide by 0 - exception thrown?
- From: William DePalo [MVP VC++]
- Divide by 0 - exception thrown?
- Prev by Date: Re: status bar
- Next by Date: Re: Divide by 0 - exception thrown?
- Previous by thread: Re: Divide by 0 - exception thrown?
- Next by thread: Re: Divide by 0 - exception thrown?
- Index(es):
Relevant Pages
|