The only thing that is required from your exception is the ability for it to be thrown. Briefly said, you can throw everything that inherits from java.lang.Throwable
class. You should, however, inherit your exceptions from java.lang.Exception
class. If you define your exception like this:
public class MyException extends Exception
{
}
it is a completely valid exception which can be thrown:
throw new MyException();
and which carries a stack trace with it. This stack trace gets printed (along with the exception type) if the exception is not caught and leaves your main
function. There is no special specification of what the exception does when not caught.
However, it is usually better for your exception class to implement at least constructors taking string message and another Exception
, simply calling super constructors with same arguments. This way you can add messages to your exception instances and wrap other exceptions in it.