Choosing not to throw exceptions like IllegalArguementException

T

Tom Anderson

Lew a écrit :

Do you think having an overrided method with return a constant Point object
worth it ?
Yes.

Don't you think it makes the original method harder to read ?

No. It makes it easier.

tom
 
A

Andy Dingley

On the other hand, it requires a better knowledge of the internals when
a bug a seen, since the program doesn't blow up compeltely.

I think your design is going wrong where you're still equating "raise
an exception" with "blow up completely".

How you handle exceptions is easily as important as how you throw
them. The last thing you want (literally, figuratively and most of all
rarely) is for a thrown exception to go so far as to cause program
termination.
 
K

Kevin McMurtrie

Robert said:
Hi,
id' like to share with you a design view i've learned since i work. When
i have to deal with nulls, i don't throw an IllegalArguementException
any more, i just return a default value (or void). It gives better
robustness to the program i think.

On the other hand, it requires a better knowledge of the internals when
a bug a seen, since the program doesn't blow up compeltely.

It depends on the context. If null or a default has meaning, return it.
If it doesn't have meaning, throw.

Falling into a rut of bad generalizations is what produces bad code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top