Solved

Error handling

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

911 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

21 Experts available now in Live!

Get 1:1 Help Now