Solved

Error handling

Posted on 2006-12-01
3
143 Views
Last Modified: 2010-04-24
Hi Experts,

   I am working with Visual C++.NET 2005 and I am looking for a way to do generic error handling.  A way to trap all errors even if I don't know what kind of error it is.

Something like this:

Try
{

}

Catch(...)
{
     // Here, I want to be able to somehow retreive the error message the OS generated
}

Thanks,
axnst2
0
Comment
Question by:axnst2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 18053425
Managed or unmanaged C++?
In both cases, catching all exceptions is strongly NOT recommended. This effectively hides program bugs. Programming guidelines require catching only expected exceptions. For example, format exception reading user input, or I/O exception working with files. Every unexpected exception must remain unhandled, this is only way to fix program bugs.
0
 

Author Comment

by:axnst2
ID: 18053641
I am working with unmanaged C++.

BTW, I know that the excepted way of handling errors is that you shouldn't catch all exceptions, that you should only catch exceptions, which are likely to happen; however, I think that's so stupid.  Exceptions that I can expect to happen, like I/O issues when I'm writing to a file, I check for 95% of the possible sources of issues before I even execute my write/read command.  Instead, I think it's much more reasonable to hve error catching for the problems I can't possibly (or very unlikely to) foresee.  All I want is to be able to tell what the error was and where it happened so that I can pinpoint and then fix the problem.


Thanks,
axnst2
0
 
LVL 3

Assisted Solution

by:Akumas
Akumas earned 250 total points
ID: 18058575
well, to my knowledge, it impossible to get exception details with catch(...).
to me, the only useage of catch(...) is to prevent release version from crash, but if you want to solve problem, you can't use catch(...) to ignore it.

maybe you can warp unknown exception in function instead of in function caller.

void functionA()
{
  try{}
  catch(...){throw ExceptionInA;}
}

int main()
{
  try{
   functionA();
  }
catch(ExceptionInA)
{
  //process exception
}
}
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
memorymap in visual studio 3 65
Visual Studio 2015 compiler settings for 32bit 1 106
c++ how to tell if the progra is ctl or mfc atl ect 6 77
SHA256 Code Signing 4 156
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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