Solved

Error handling

Posted on 2006-12-01
3
141 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now