Best Practices for Exception Handling
Subject:   A few things
Date:   2003-12-05 08:17:50
From:   javid
I like the article in general.

I don't agree that you shouldn't throw custom exception. You said to avoid this. In fact, I would argue the exact opposite within a Test First Design model. If you don't throw custom exceptions, you can get false positives in your unit-tests. For example, lets say you are testing that a method throws RuntimeException, because of a SQLError that you wrapped, but it instead it throws RuntimeException because of something else. Your test would still pass, but it is a false positive. If you throw a unique exception, you don't run into that problem.

Also, you seem to advise people to never deal with the exception, and always throw it. If there is a non-recoverable application failure, I think you should always throw it, and let a top-level exception handler deal with displaying the message. Otherwise, you should try to recover in the catch block if you can. For example, if you are attempting to open a file, and you can retry 4-5 times until the lock is released, then you should try to recover from the failure, not just throw the exception.

Otherwise, I think it was a good article.

1 to 2 of 2
1 to 2 of 2