This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 ]
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?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
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!)
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???
"JavaRanch, where the deer and the Certified play" - David O'Meara