I Am So Tempted to Write the "Exception Handling in .NET" E-Book

I've had it.

I'm done with seeing exception handlers in .NET written that catch every kind of exception.

This one finally broke me:

public bool IsAuthorized()
{
   try
   {
      return AuthorizationManager.DoSomeKindOfFancyAuthorizationChecking();
   }
   catch (Exception)
   {
   }

   return true;
}

Guess what this returns if there's an exception...

ARGH!!!!

If I can find the time, I'm going to write the 50-page e-book on exception handlers in .NET and charge $1 for it (or hell, just give it away for free!). Get it into every .NET developer's hands and make them follow it. Update it as soon as others find issues with it.

It's time.

* Posted at 07.16.2008 02:09:25 PM (Last Update: 07.19.2008 01:24:25 AM) | 8 comments | Link | RSS *

Comments

# Yep., from Peter Bromberg at 07.16.2008 03:20:02 PM

Totally agree. Developers are given a tool, they don't RTFM, and proceed to abuse it.

# Do it!, from jb at 07.16.2008 03:29:32 PM

Do it. I'd buy it. If developers were honest with themselves, most would admit they don't fully grok how to do exception handling the "right" way. They just hack stuff out to get by.

# the real WTF is in .NET and Java, from bex at 07.16.2008 07:55:01 PM

Frankly, I can't think of a single instance where exceptions should ever do less than this:

catch (Exception e){
e.printStackTrace();
}

So frankly... why doesn't Java and .NET just ALWAYS do that? Force people to use a VM flag to shut it off.

It wouldn't stop your specific problem, but still...

# Yes, from Chris Sutton at 07.16.2008 09:36:36 PM

I'd buy the book if you wrote it.

Chris

# That's the problem, from Jason Bock at 07.17.2008 09:14:44 AM

bex, Catching the exception type without rethrowing it is just plain bad. Adding a flag to the VM wouldn't solve anything.

# actually bex..., from Chris at 07.17.2008 01:37:25 PM

...what would be better is for the compiler to not allow you to catch plain ol' System.Exception in the first place. That's prolly a little harsh though. And your example is the reason behind this blog post.

I've ranted about this topic before, here's what sux. If the offenders won't read the manual, they're not gonna read the ebook either.

# I'd read it!, from David Cumps at 07.18.2008 05:25:26 AM

I'd love to read an ebook about that, I'm interested in knowing how to properly deal with exceptions

# Exception hierarchy stupidity, from Jeff Brown at 07.19.2008 01:24:22 AM

Pity the .Net exception hierarchy sucks making it difficult to tell serious runtime errors apart from other exceptions that can reasonably be consumed / logged without ill effect.

Add a Comment

(*) = Required field
Name (*):

E-Mail (*):

Web Site:

Title (*):

Comments (*):

Enter the code you see (*)



Quote
"Knowledge speaks, but wisdom listens." Jimi Hendrix
Twitter History
follow me on Twitter
Blog History