SteveK
Tue Sep 28 13:20:18 CDT 2004
Doug, this is all usefull and sound advice, thank you.
I plan to give some time to finding the bug that is passing junk to
GetRecordTypeId as that is indeed the problem. The code is such a rat's
nest of band-aides and hacks that I really don't intend to spend too much
time "fixing it correctly"
It would be valuable as a learning experience to hunt it down and that is my
motivation for doing that, but for the moment, I just want to handle this
junk pointer problem as gracefully as possible.
I will read about structured exceptions, hopefully there will be some code
samples in the link that will show me a trick to gracefully step over(or
around) this stinking pile of trash! ;)
Thanks again!
"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:q49jl01fqnlip9v7vhi6irdvvv2igk1866@4ax.com...
> SteveK wrote:
>
> >There is a tool that we use here at work. The guy that wrote it has since
> >quit and I was asked if I would like to take it over (I'm learning to
> >program and the co. supports that) with that said, the code is really
messy
> >and rather than fix ir "correct" i have started to design a new version
from
> >the ground up, I am still responsible for keeping the old one running
until
> >I roll out the new one.
> >
> >OK, so I have a crash that happens randomly and I have asked the people
here
> >to send me their logs when they crash, I have narrowed it down to one
> >operation and I don't understand why it's happening. I just thought I
could
> >wrap it in a try/catch and handle it from there.
> >
> >Here is the code:
> >inline byte GetRecordTypeId(void* pV)
> >{
> > if(pV)
> > {
> > try
> > {
> > return *(byte*)pV;
> > }
> > catch(char* e)
> > {
> > theLog.WriteError(e, __FILE__, __LINE__);
> > }
> > }
> > return kRecordTypeUndefined;
> >}
> >
> >
> >However, this appears to do nothing. It still crashes just the same as
if
> >there was no try block. From what I understand, the above code should
have
> >worked fine. What am I missing?
>
> Exceptions don't work like that. If dereferencing pV crashes, it's
> generating a Windows structured exception, not a C++ exception, and
> certainly not a char*. People sometimes (usually wrongly) want to catch
> structured exceptions in catch(...), and for more on that, see:
>
>
http://members.cox.net/doug_web/eh.htm
>
> Note also that even if you were to catch the exception, the __FILE__ and
> __LINE__ usage probably wouldn't help you much, because they reflect the
> file and line in which they appear. Your problem appears to be one of
> garbage input to GetRecordTypeId, and what you have tried won't tell you
> where the call came from. IOW, the above is not giving you any new
> information, as you already seem to know it's crashing there. In the
> debugger, you could easily determine who called GetRecordTypeId by looking
> in the call stack window. If you don't know how to use the minidump Jochen
> mentioned (I confess I don't know how to do this - any tips, Jochen?), and
> you can't otherwise debug the crash, you can always search your source
code
> for GetRecordTypeId. If that function is called from just a few places,
you
> might be able to spot the problem without too much trouble. In addition,
you
> can always instrument your code with OutputDebugString calls and view the
> output using Sysinternals DbgView:
>
>
http://www.sysinternals.com/ntw2k/freeware/debugview.shtml
>
> --
> Doug Harrison
> Microsoft MVP - Visual C++