Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about throw

 
y bin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which sequence is corrrect?


or



May anybody tell me ? thanks!
 
Irina Goble
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic