clamum
Lifer
I have been wondering for some time about how others handle exceptions. I am concerned primarily with Windows applications, specifically .NET, but feel free to add your expertise in other areas if it's relevant (most of which it should be; exception handling in Java would be similar I'd think). I did some searching here and a bit on the Internet and found Vexing Exceptions which was alright I guess.
But I'm interested in what you guys do and think.
Most of the newer applications at my job are structured like this:
Every method is like that, big or small. Part of the reason is due to a practice begun long ago that was because, from what I gather, when an exception occurred they were having issues with not having the full, correct stack trace. But even ignoring that stack trace thing, we still put the entire method in a try/catch block.
Now I was always of the impression that you should only put a try/catch block around code that might blow up, such as reading/writing files, opening or executing databases and queries, and so on.
One more thing that is particular to where I currently work. The applications we run are part of a system that runs every two hours (to be simple about it). Every two hours, this big process starts and these applications get triggered to run sooner or later. Any exception in them will display an error MessageBox on the screen which a monitoring app sees. The monitoring app takes a screenshot and sends out an email with the image attached and the exception message, and someone then fixes the issue. We deal with tons of customer/client data, and it might be just due to that in some way (it's usually not an *app* bug per-se, but due to some other data or database state).
Anyway, I was wondering what other Windows app developers do about exceptions. I have a feeling putting every method in a try/catch block is crappy design, but it works for us. We get the stack trace, the error gets handled (the app is frozen with the MessageBox up of course until we resolve it). I know it's probably not the "proper" way to write an app, but if it works for us, so what? One thing that is a drawback of this is that when an exception does occur and we gotta find the exact line of code that cause it, it can be a little tricky because we don't have a line number to go to and have to try and determine exactly which line it was.
So... lemme hear your exception handling wisdom!
But I'm interested in what you guys do and think.
Most of the newer applications at my job are structured like this:
Code:
private void DoSomething(string param1)
{
try
{
// do stuff
}
catch (Exception ex) { }
}
Every method is like that, big or small. Part of the reason is due to a practice begun long ago that was because, from what I gather, when an exception occurred they were having issues with not having the full, correct stack trace. But even ignoring that stack trace thing, we still put the entire method in a try/catch block.
Now I was always of the impression that you should only put a try/catch block around code that might blow up, such as reading/writing files, opening or executing databases and queries, and so on.
One more thing that is particular to where I currently work. The applications we run are part of a system that runs every two hours (to be simple about it). Every two hours, this big process starts and these applications get triggered to run sooner or later. Any exception in them will display an error MessageBox on the screen which a monitoring app sees. The monitoring app takes a screenshot and sends out an email with the image attached and the exception message, and someone then fixes the issue. We deal with tons of customer/client data, and it might be just due to that in some way (it's usually not an *app* bug per-se, but due to some other data or database state).
Anyway, I was wondering what other Windows app developers do about exceptions. I have a feeling putting every method in a try/catch block is crappy design, but it works for us. We get the stack trace, the error gets handled (the app is frozen with the MessageBox up of course until we resolve it). I know it's probably not the "proper" way to write an app, but if it works for us, so what? One thing that is a drawback of this is that when an exception does occur and we gotta find the exact line of code that cause it, it can be a little tricky because we don't have a line number to go to and have to try and determine exactly which line it was.
So... lemme hear your exception handling wisdom!