473,503 Members | 9,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.

Sep 13 '06 #1
2 24496
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/

Sep 13 '06 #2
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.

"Oleg Starodumov" <com-dot-debuginfo-at-olegwrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...
>
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/



Sep 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
4094
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
5
3170
by: comp.lang.php | last post by:
$orderBy = 's.app_date desc, s.last_name asc, s.first_name asc, s.mi asc'; if ($_REQUEST) { $ascArray = array('asc' => 'desc', 'desc' => 'asc'); // ARRAY OF ALL ORDERING POSSIBILITIES $junk =...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.