• Post Reply Bookmark Topic Watch Topic
  • New Topic

Resolved: exceptions names  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have some issues with the name .My exercise tell some exceptions to name it like this : InvalidGpException .Can i give every name i want to an exceptions? this name i give it on a method? on a class?where?and i have the power to name with what name i want?

when i write throw i refer to a class or i can refer to a method?
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your exception classes should always extend java.lang.Exception but maybe indirectly; you can extend a subclass of Exception. The name of an exception class should always say what it is used for, and should always end “Exception”. You should look through the existing kinds of Exception to find the best kind of Exception to extend.
You can only throw a (non‑null) instance of Throwable, which of course includes any instances of its subclasses. Nothing else.

Look in the documentation for Exception to find some different kinds of Exception. If you want an unchecked Exception, look at the subclasses of RuntimeException. For more details, you have already been given a link to the appropriate Java™ Tutorials section.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!