Solved

Error handling

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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