On Thu, Apr 1, 2010 at 9:12 AM, Bertrand Delacretaz
<[email protected]> wrote:
> Hi,
>
> I've been thinking about the information conveyed by exceptions, and I
> think we could do much better with naming them.
>
> Using the unchecked SlingException as a base is certainly a good idea,
> but stack traces often get lost, and end users often have a hard time
> reporting exactly what happened when they get an exception.
>
> To fix this, I suggest using a class naming pattern like:
>
> package foo.bar;
>
> class Wiz {
>  static class
>    PackageFooBarClassWizMethodGetSomethingProblemComputeException
>    extends SlingException {
>    ...
>  }
>
>  void getSomething() {
>    if(...something bad happened...) {
>      throw new
> PackageFooBarClassWizMethodGetSomethingProblemComputeException (...);
>   }
> }
>
> Using a strong naming convention like this for exceptions would make
> it much easier to find out where a problem happened, without having to
> hunt for stack traces. Any Sling user can then report precisely where
> a problem happened.
>
> In the above example, the
> PackageFooBarClassWizMethodGetSomethingProblemComputeException name
> makes it very clear that there was a problem in the getSomething
> method of the Wiz class in package foo.bar, and the problem is a
> ComputeException. Bit of a longish name, but we all have cool IDEs,
> right?
>
> Exceptions classes like
> PackageFooBarClassWizMethodGetSomethingProblemComputeException should
> probably be generated, as it's somewhat boring code to type. We can
> think about creating a few annotations, a java code preprocessor or
> bytecode generator, a maven plugin and some javadoc extensions if we
> agree on the basic idea. Maybe we should organize a hackathon soon to
> design this, as it's a big change in the exceptions paradigm. And
> maybe create a new JSR, as we want Sling to be based on standards.
> Again, if we agree on the basics. Thinking about it...maybe JVMs could
> generate those class names based on where the Exception is thrown.
> Hmm....
>
> I don't think I've seen this used in any java software yet, so it
> might look unusual but being different is a great way of making Sling
> more visible. I'm going to reserve the spp.org domain ASAP as we might
> need a place to describe this new revolutionary technique. Tell them
> you saw it here first!
>
> WDYT?

This sounded so great to me, and knowing how much Bertrand appreciates
automated tests, I went ahead and implemented tests for all exceptions
we will possibly need.

Take a look (esp you, Bertrand), and tell me what you think:
http://tinyurl.com/2g9mqh

-- 
Vidar S. Ramdal <[email protected]> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00 / +47 21 531941, ext 2070

Reply via email to