Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can't catch C++ exception

Posted on 1998-03-27
6
Medium Priority
?
575 Views
Last Modified: 2013-11-20
I have a case where I cannot catch exceptions generated by CRecordset::MoveNext().  Other exceptions are caught by my exception handler (catch block), but this one results in only the following message appearing in the Output window of the debugger.

First-chance exception in ... Microsoft C++ Exception.

Then control returns to the statement following the MoveNext() that caused the exception.  What might be going on?  Do you have any suggestions for debugging this problem?  Are we looking at possible stack corruption?

Thank you,
Bruce O'Reilly and Andre Nguyen
0
Comment
Question by:boreilly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:gelbert
ID: 1317286
When you are in debug mode in VC++ 5.0 go to menu item "debug" subiten "Exeptions". Select all listed type of exceptions and change status to "Stop Always". It make debugger stop when exceptions arise instead of displaying message in output window
0
 

Author Comment

by:boreilly
ID: 1317287
I have already tried what Gelbert suggested.  Using that, I see the exception being raised deep down in the ODBC DLL after CRecordSet::FetchData() calls ::SQLExtendedFetch().  The problem is, what could cause the exception to be uncatchable by my handler?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1317288
The exception raised is not really a C++ exception.  Check the help about SEH (structured exception handling) and how to catch such exceptions in C++.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:yonat
ID: 1317289
Maybe the exception is caught BEFORE it reaches your catch clause.

BTW, catch(...) catches all exceotions, including the structured exceptions that alexo mentioned.
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 400 total points
ID: 1317290
The behaviour you note is entirely by-design and completely normal.

You're calling into some other functions. Those functions probably call other functions, too. When the exception is raised, the environment tries to find an exception handler. It searches by looking at the current function, the function that called it, the function that called that one, and so on--unwinding the stack of function calls.

You're not hitting your own catch() block because some other catch() block is handling the exception, and that's that. The message from the debugger is entirely normal: when an exception is thrown in a process that is being debugged, the debugger is notified _immediately_. The debugger can stop execution before the environment tries to find a handler, or it can let the thread that's throwing the exception try to find a handler.

Since the author of the ODBC driver you're using knew that an exception might happen, they wrote a catch() handler of their own to manage the execption. The exception is thrown and you see the message in the debugger. But the environment ends up finding the catch() handler the driver itself implements and executes that handler. The handler doesn't rethrow the exception, so processing continues on as normal. And that's that: you're not offered a chance to catch() the exception because someone else closer to the exception has already handled it. Even if you got the chance to handle the exception, you wouldn't know what to do: you don't have the source code for the driver, and the throw structure that the driver uses internally aren't documented.

If you've set the "Exceptions" option that GELBERT talks about to "Stop Always", the debugger will immediately break when the exception is thrown. That can help you debug the code generating the exception or the code which is going to find the exception handler.  Otherwise, if that option isn't set for the type of exception being generated, the debugger returns control immediately to the thread that threw the exception so it can search for a handler.

That's why a "first-chance exception" has it's name: the debugger is offered the first chance at handling a rasied exception. The message is just informational. If there is no debugger attached to the process, the thread will immediately begin search for a handler. If a handler is found, it executes. If no handlers is found, the operating system kicks the process out of memory with an "unhandled execption" error.

You can find lots of information about the mechanism at work here by reading.  See the KB article Q105675, for example, for a description of the messages the debugger generates.  Or, read up on the "Exception Handling" topics in the SDK--like "Exception Handling for Debugging".  Or, read the "Understanding the Debugger" article I wrote for Visual C++ Developer; see http://www.pinpub.com/vcd/home.htm for more information about that magazine.

The exception raised is _certainly_ a C++ exception; if it wasn't, it wouldn't have the "Microsoft C++ exception" type ID. An systems exception has a type ID describing the exact error that ocurred.

A catch(...) block will catch all thrown exception types that are scoped for it--it still won't catch exceptions of _any_ type that are handled by more deeply scoped catch() handlers.

.B ekiM

0
 

Author Comment

by:boreilly
ID: 1317291
Mike,
Thank you very much for the help.  What threw me off is that I could not find the exception handler when tracing this with the debugger, but that's not too surprising given that I don't have source to the Access '97 ODBC driver.  Your book is really great.  Every MFC programmer in this place owns an copy and we all use it regularly.  We just call it "Mike's book".

Bruce O'Reilly
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question