473,569 Members | 2,764 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 24505
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******** ******@TK2MSFTN GP03.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
4110
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 Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:"...
5
3185
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 = preg_match('/(+)a|sc(,?.*$)/i', $orderBy, $matchArray); $orderBy = substr($orderBy, 0, strpos($orderBy, $matchArray)) . ' ' . $ascArray] ....
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
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 we have to send another system
0
936
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.