2

Is it advisable for my own DAO class to throw a SecurityException in its constructor if it fails to authenticate to the data store?

The Java documentation says that SecurityException is to be used by SecurityManager, which suggests to me that it's not appropriate for use by other classes.

If not SecurityException, is there a better Java exception class to use or should I just use an application exception?

Thanks!

HolySamosa
  • 9,011
  • 14
  • 69
  • 102
  • There's nothing wrong with writing your own exception with its own semantics. If the Javadoc says not to do something, I wouldn't do it. – Jonathan Jan 23 '12 at 15:31

1 Answers1

0

You can always write a new Exception which makes sense in your domain. Say "AuthenticationFailedException". You can make it extend java.lang.Exception to make it checked or java.lang.RuntimeException.

Pavan
  • 1,245
  • 7
  • 10