• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

favor the use of standard exceptions

 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To continue a conversation began in The Beginner's Forum (which is also the best forum at JavaRanch):
Originally posted by Volodymyr Shram:
So, you want to say, that it is better to use standard Exception over creating a new type (extended Exception)? Would you so kind to explain why do you think so, or start new thread for this discussion -- it's very interesting really.
When I have some more time, I'll be glad to discuss my opinions. In the mean time, I'm sure some of ya'll advanced-type folks have some good ideas.
[ November 05, 2002: Message edited by: Dirk Schreckmann ]
 
Volodymyr Shram
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
To continue a conversation began in The Beginner's Forum (which is also the best forum at JavaRanch):
When I have some more time, I'll be glad to discuss my opinions. In the mean time, I'm sure some of ya'll advanced-type folks have some good ideas.

Hi, Dirk!
Of course, it's very good practice -- to use existing Exceptions for non-intrinsic exception
situations: to use NumberFormatException instead writing new NegativeNumberFormatException class. But will you remember how do you use your standard Exceptions for one or years after finishing your project? Will your co-workers involved to the project be agry with your design?
As for me, it is better to write new Exception class for individual needs: if you get some
exception at server side and want to send it to client, write public class ServerDatabaseException extends Exception implements java.io.Serializable; If you need to send message to client with "A new account with a negative balance cannot be created." string write NegativeNumberFormatException with incapsulated field which you can print with your error message or maintain this field data for your needs inside catch-block.
As for me, it's very handly and much clearer than to use standard exception classes for that puroses.
What do you think about?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://c2.com/cgi/wiki?DesigningWithExceptions has some good tips on how to use Exceptions
 
Norm Miller
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joshua Bloch - Effective Java
Item 42. Prefer the use of standard exceptions
1. Makes your API easier to learn and use because it matches established conventions.
2. Easier to read programs not cluttered with unfamiliar exceptions.
3. Fewer exceptions means a smaller memory footprint and less time spent loading classes.
(Buy the book!)
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree - buy the book!!
We gotta get Joshua back to hang out here some more. He came for a while - but then got all busy writing that 1.4 release and forgot all about us .

"To continue a conversation began in The Beginner's Forum (which is also the best forum at JavaRanch):"

Really Dirk - you KNOW Beginners is Kindergarten, Intermediate is sortta like High School and Advanced is University level.
Almost everyone I know has fonder memories of High School than Kindergarten .
Hey - How would you like a forum with all PINK font???
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic