joe_pool_is
Contributor
The more I learn about exceptions, the more I feel like I should *not* be catching and dismissing general exceptions in my code like I do:
So, what I've been trying to do is catch the exceptions that could be thrown by particular routines, but I don't know which ones need to be caught and which ones are obvious checks that don't need catching.
Take the ArgumentNullException. If I do a simple check on my object,
can I eliminate the ArgumentNullException?
For sending a simple email, I find myself catching about 5 exceptions:
Is this ridiculous or is it just me?
So I go to build my application, and VS2005 throws up and error:
Sometimes I just want to go back to catching the general exceptions, but I also want good code.
Code:
try {
DoThis1();
} catch (Exception err) {
LogError(err);
}
Take the ArgumentNullException. If I do a simple check on my object,
Code:
if (obj != null) {
DoThis2();
}
For sending a simple email, I find myself catching about 5 exceptions:
Code:
try {
SmtpClient client = new SmtpClient(strIpAddress);
client.Send(email);
} catch (SmtpFailedRecipientsException) {
// handle it
} catch (ArgumentNullException) {
// handle it
} catch (SmtpException) {
// handle it
} catch (InvalidOperationException) {
// handle it
} catch (ArgumentOutOfRangeException) {
// handle it
} catch (ObjectDisposedException) {
// handle it
}
So I go to build my application, and VS2005 throws up and error:
Where is the documentation on what order to catch my exceptions in? I found documentation on Exceptions on MSDN, but nothing telling me what order they can be called in.A previous catch clause already catches all exceptions of this or of a super type ('System.InvalidOperationException')
Sometimes I just want to go back to catching the general exceptions, but I also want good code.