This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes about throw Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "about throw" Watch "about throw" New topic
Author

about throw

y bin
Greenhorn

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


or



May anybody tell me ? thanks!
Irina Goble
Ranch Hand

Joined: May 09, 2004
Posts: 75
Hi,

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
 
Similar Threads
Enthuware mock test question (hashCode)
operator precedence & associativity
exception
Chained exception
When is Stacktrace printed in Exceptions?