Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
use of assert in Java [vs. exceptions]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Lew, post: 3871420"] In Java, if the arguments are integers then division by 0 with the '/' operator throws an 'ArithmeticException'. Is that "defensive programming"? Does it make the '/' operation slow? In Java, if the arguments are of a floating-point type, e.g., 'double', then division by zero yields a double value ('NaN' or signed infinity). Is that "defensive programming"? Does it make the '/' operation slow? It seems that Java is able to define arithmetic '/' such that it can handle all possible inputs without running into the performance problems that some seem to think are a risk. If one wants to modify the behavior of division by zero, say with integers to avoid causing an 'ArithmeticException', one can do the optimized value check that Stefan suggests. Presumably this would be inside a method that accepts a value for 'y' and forwards the action to 'f()' or '/' as needed. Is that "defensive programming", or is the check outside the loop for 'y == 0' and corresponding delegation to 'f()' just "good programming"? [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
use of assert in Java [vs. exceptions]
Top