wood burning stoves 2.0
The moose likes Beginning Java and the fly likes about throw Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about throw" Watch "about throw" New topic

about throw

y bin

Joined: Feb 18, 2004
Posts: 4
which sequence is corrrect?


May anybody tell me ? thanks!
Irina Goble
Ranch Hand

Joined: May 09, 2004
Posts: 91

Both examples are legal and both waste a few lines of code.
For integers dividing by zero will throw ArithmeticException anyway. You could check for a zero divider before the division operation to prevent from throwing and do some graceful recovery.
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
IMHO, you don't need to throw any exception nor check for divsor equal to zero inside your method.

What you could do is to ensure that the divsor you passed into the method is non-zero. If it is zero, don't pass it in. Or you could put this method in a try-catch block instead when you're using.

SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
I agree. Here's the link: http://aspose.com/file-tools
subject: about throw
It's not a secret anymore!