|
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.
|
My opinion is that custom exceptions always have at least one precious piece of information for client code : their type !!!!
Suppose I create an XYZService that can throw XYZException, simply extending RuntimeException without any additional attribute or method. The ture added value of my custom exception is that I will be able in the client code to filter exception handling precisely for exceptions coming from this XYZService.