+3  A: 

The chief disadvantage to Option 2 (a common exception + enum) is that you lose some of the utility of checked exceptions. A method pretty much has to say simply "something framework-related might go wrong":

public void foo()
throws MyFrameworkException

...rather than "x or y might go wrong":

public void foo()
throws SomethingWentWrongException, SomethingElseWentWrongException

It means a function that may need to handle one framework exception has to be prepared to handle any of them, whereas if you're specific, a function need only be prepared to handle the exceptions that are thrown by the framework methods it calls.

So for me, a hierarchy such as Option 1 (it needn't be quite so flat, if a structure suggests itself) is the way to go. That said, there are people who don't like checked exceptions at all, and for them I suspect the above is not a compelling argument. :-)

Edit And picking up duffymo's point: I've assumed you were talking about exceptions you really did have to create. Absolutely throw standard exceptions wherever it makes sense (which is nearly everywhere). Don't create your own MyFrameworkIllegalArgumentException, for instance, just use IllegalArgumentException (or its various subclasses).

T.J. Crowder
To add to this: Option 2 look like error codes disguised as exceptions.
Etienne de Martel
Yes, the plan is to never rethrow exceptions in new wrapped exceptions and also to allow certain java/third-party-lib exceptions to be propagated outside of my project methods. So many of my methods will throw custom exceptions + other java exceptions.
Andy
@Andy: Excellent, yeah, I figured you probably meant that.
T.J. Crowder
+2  A: 

I would go with exceptions extending java.lang.RuntimeException with descriptive class names.

If you have so many business-specific exceptions that this becomes oppressive, it means you're probably doing it wrong.

See Joshua Bloch's advice about favoring standard exceptions.

duffymo
`java.lang.Runnable`? Did you mean `RuntimeException`?
T.J. Crowder
Yes, I did. Going too fast; distracted. Thanks for the correction.
duffymo
+1  A: 

I wouldn't inherit from a generic MyFrameworkException, as long as you dont provide any functionality in there common to all projects. Else, always extend Exception.

Normally you should throw meaningful exceptions at domain/layer boundaries. So regarding your question, you should go with option 1, having in mind the point above. Option 2 would increase code complexity, as you will always have to check for the exception type to determine what went wrong. Let the exception class speak for itself.

MicSim
MyFrameworkException would have some basic functionality and would allow me to identify/group exceptions that originate from the whole suite of code, so I still kinda want to use it as a base.
Andy
I would agree with Andy - I see little or no good reason to extend anything other than the java.lang base classes.
duffymo