This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NX: Additional methods in Exceptions  RSS feed

 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my specs, Sun says the following about the unimplemented exceptions that their provided interface references (for example, like the RecordNotFoundException).

Each must have a zero argument constructor and a second constructor that takes a String that serves as the exception's description.

So...
1. Does this mean I can only have those 2 constructors? (they don't specifically say ONLY these constructors, but is it implied?)
2. Or can I add an additional one if needed? (I want to add one that takes both a String and a Throwable.)
Thanks.
TJ
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TJ,
You can add any other convenient constructors that you want to but you MUST provide the ones they specify or risk automatic failure. I added one to RecordNotFoundException that takes an int recNo argument. Exceptions are supposed to be convenient to build and use.
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ken. Good idea on the additional argument to RecordNotFoundException.
TJ
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!