exception handling

programming languages

Exception-Driven Development

If you're waiting around for users to tell you about problems with your website or application, you're only seeing a tiny fraction of all the problems that are actually occurring. The proverbial tip of the iceberg. Also, if this is the case, I'm sorry

By Jeff Atwood ·
Comments

programming languages

Please use .ToString() responsibly

I’ve seen this kind of code a lot recently: try { int i = 0; int x = 0; Console.WriteLine(i / x); } catch (Exception ex) { Console.WriteLine(ex.Message); } This results in the following output: Attempted to divide by zero. Unless there’s some compelling reason you need an ultra-terse version

By Jeff Atwood ·
Comments

guids

Mastering GUIDs with Occam's Razor

Do you remember the scene from the movie Full Metal Jacket where the marines recite the USMC creed? It’s a little known fact, but programmers have a similar creed: This is my GUID. There are many like it but this one is mine. My GUID is my best friend.

By Jeff Atwood ·
Comments

c#

TryParse and the Exception Tax

In .NET 1.1, TryParse is only available for the Double datatype. Version 2.0 of the framework extends TryParse to all the basic datatypes. Why do we care? Performance. Parse throws an exception if the conversion from a string to the specified datatype fails, whereas TryParse explicitly avoids throwing

By Jeff Atwood ·
Comments

.net

Improved Unhandled Exception behavior in .NET 2.0

I recently posted a question about console apps and AppDomain.CurrentDomain.UnhandledException – specifically, why doesn’t it work as described in the MSDN documentation? I even filed an official bug report on this. I guess it worked, because Microsoft’s Jonathan Keljo was kind enough to explain this behavior in

By Jeff Atwood ·
Comments

.net framework

Console apps and AppDomain.CurrentDomain.UnhandledException

This one has me stumped. I’d swear this behaved differently prior to .NET 1.1 service pack 1 (and/or XP SP2), but I can’t prove it. As reported by a CodeProject reader, you’ll get the standard .NET crash dialog in a console app, even if you’

By Jeff Atwood ·
Comments

windows forms

If an Exception happens in Form.Paint, does anyone catch it?

In a previous post, I mentioned the old VB6 trick of deferring form work until the Form.Paint event in order to provide a (seemingly) responsive interface to the user. Well, in the .NET world there’s one strange side effect when you do this. Let’s say you had

By Jeff Atwood ·
Comments

.net framework

Creating Even More Exceptional Exceptions

In response to my previous post decrying the lack of a master list of Exception classes for .NET, a helpful reader pointed out a clever little utility buried in the .NET SDK: Program FilesMicrosoft Visual Studio .NET 2003SDKv1.1Binwincv.exe Wincv works well, but it doesn’t allow me to

By Jeff Atwood ·
Comments

exception handling

Creating More Exceptional Exceptions

I find myself throwing plain old System.Exception far too often. If only I had a complete reference of the many default Exception classes Microsoft provides, like the one Chris Sully provides in his article. That’s good as a starting point, but I don’t see things like System.

By Jeff Atwood ·
Comments

.net

Throwing Better .NET Exceptions with SOAP and HTTP

In a recent entry,  I bemoaned the lack of good global error handling options for .NET Web Services. By “good” I mean “easy,” like the Application_Error event in Global.asax for ASP.NET websites. I have a pretty solid web-oriented generic unhandled exception class, which is documented in my

By Jeff Atwood ·
Comments

asp.net

User-Friendly ASP.NET Exception Handling

I just posted a new article to CodeProject, User Friendly ASP.NET Exception Handling. I casually mentioned in the original article that I didn’t think a global unhandled exception management class designed for WinForms and console apps was appropriate for ASP.NET apps, and that I had a separate-but-equal

By Jeff Atwood ·
Comments

exception handling

Rethrowing Exceptions

There’s a bit more subtlety to rethrowing exceptions than most developers realize. Although this topic is covered very nicely at The .NET Guy blog, here’s another example: Try session = smgr.getSession(_strDocbaseName) Catch ex As Exception If ex.Message.IndexOf("authentication failed") > 0 Then Throw

By Jeff Atwood ·
Comments