whats "First-chance exception", how do i fix it?

  • Thread starter Thread starter Abubakar
  • Start date Start date
A

Abubakar

Hi all,

I'm writing an app in vc++ 2k5 (all native/unmanaged). This application does
a lot of multithreading and socket programming. Its been months since I'm
developing this application, at this point a lot of it is working just fine,
my app running fine, threads r being made and destroyed, memory is being
dynamically allocated at God knows how many places and ,hopefully, getting
deallocated as well. Its just by coincedence I happened to look at my output
window when my application is running in the debugger, and I see the
following line printed thousands and thousands of times (each line has
different addresses):

First-chance exception at 0x7c4f5dc2 in myapp.exe: 0xC0000005: Access
violation reading location 0x3233342e.

As I said everything is working fine, app is not crashing anywhere. Windows
Task Manager is not showing any *significant* memory leaks. Why is this line
being printed, I mean where should I look for the possible bugs, what are
the typical things that a c++ programmer mistakenly does that causes this
exception? Just by reading it I 'm sure something really wrong is happening
and it just so happens that its not crashing my app, but I dont wanna ignore
it and want to fix it.

Regards,

-ab.
 
Its just by coincedence I happened to look at my output
window when my application is running in the debugger, and I see the
following line printed thousands and thousands of times (each line has
different addresses):

First-chance exception at 0x7c4f5dc2 in myapp.exe: 0xC0000005: Access
violation reading location 0x3233342e.

As I said everything is working fine, app is not crashing anywhere. Windows
Task Manager is not showing any *significant* memory leaks. Why is this line
being printed, I mean where should I look for the possible bugs, what are
the typical things that a c++ programmer mistakenly does that causes this
exception?

The message means that an exception is raised somewhere (at the specified
address). Since the application does not terminate with a second-chance exception,
it also means that the exception is handled somewhere.

Since the number of exceptions is big, it is possible that there is a problem
with the application (though not necessarily - may be this exception is expected
and handled). You can check what is going on if you ask the debugger
to break on first chance exceptions. For this, open Exceptions dialog, find
the exception mentioned in the debug output (in this case it is "access violation"
exception, should be under Win32 exceptions node), and select checkbox called
"Thrown" for the given exception.

Next time the debugger should break immediately at the moment when
the exception is raised. You should usually check two things:
- Why is this exception raised (see the call stack and parameters of the functions
on the call stack - you might need good symbols for system dlls to do this,
see VS debugger documentation on how to download symbols from the symbol server)
- Who could handle this exception (see the call stack for functions with
exception handlers)

This should usually tell you if the exception is dangereous or not,
and what could be done to get rid of it if needed.

Oleg
http://www.debuginfo.com/
 
Hey Thanks so much. I just tried this and found the bug so easily. Its a
network related functionality in my code that was causing this problem.

I think this exception should be enabled by default when we install the
vc2k5 so that developers know about this kind of functionality problem early
in their development.

Regards,

-ab.
 
Back
Top