File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes favor the use of standard exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "favor the use of standard exceptions " Watch "favor the use of standard exceptions " New topic
Author

favor the use of standard exceptions

Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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 ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Volodymyr Shram
Ranch Hand

Joined: Oct 17, 2002
Posts: 47
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

Joined: Jul 11, 2001
Posts: 14112
http://c2.com/cgi/wiki?DesigningWithExceptions has some good tips on how to use Exceptions


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
Norm Miller
Ranch Hand

Joined: May 21, 2002
Posts: 56
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

Joined: Sep 29, 2000
Posts: 8521
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: favor the use of standard exceptions
 
Similar Threads
General Questions
Final review - PLEASE READ
Conditional Operator
NumberFormatException
Generics type erasure.