JimT Utah

So I write code using a try-catch block. The try can fail for a number of reasons. In the specific instance I'm concerned with, the fault can be "file not found", "can't read the file", "server time out", "security exception", or possibly others I haven't seen. Is there a list somewhere of exception messages When I look up the manual pages for DataSet.ReadXml, "security exception" is the only one listed, even though there are several others I have seen, and the text of the message is not given. How do I know how to react if I can't distinguish one message from another

Is there a secret trick to parsing exception messages


Re: Common Language Runtime How do I parse Exception Messages?

nobugz

You don't parse the Exception.Message property, that's just for human eyes. You filter exceptions by catching specific types:

try {
// Do stuff that can throw
}
catch (FileNotFoundException ex) {
// Recover from missing file problem...
//...
}
catch (SecurityException ex) {
// Recover from security problem...
//...
}
// Etc.

You are usually doing something wrong when you make big lists of catch clauses. Catching SecurityException for example is almost never appropriate, it will require a configuration change to solve. Something you can't do in your catch handler. Only catch an exception if you can recover from it gracefully and let your app continue in a meaningful and functional way.





Re: Common Language Runtime How do I parse Exception Messages?

JimT Utah

It looks like I didn't explain myself well enough. I want to know what exceptions to look for / to expect to see. Is there a list

I appreciate the advice that I should code the catch by exception name rather than trying to parse the message, but I still ned to know what's possible either way. The documentation is not as helpful as it could be, because the three exceptions that actually occurred were not listed in the Exceptions paragraph for DataSet.ReadXml, and the one that was listed, SecurityException, never occurred.




Re: Common Language Runtime How do I parse Exception Messages?

nobugz

The "Exceptions" section in the MSDN library topic is the only list available. To identify an exception, click the View Detail link in the debugger's exception dialog. The exception type is listed in the upper left cell.