.net - Why, In Java arithmetic, overflow or underflow will never throw an Exception? -
during java arithmetic operation , jvm not throw underflow or overflow exception. many time come across unexpected results , wondering went wrong.
while in case of .net technology have overflow , undeflow exception.
so question , why java design not throw exception during arithmetic operation
this combination of factors:
- the big languages prior java used unchecked arithmetic. well-known algorithms prone numerical overflow tended account potential overflow without relying on checked arithmetic.
- checked arithmetic introduces significant overhead in algorithms making heavy use of arithmetic instructions, put java @ substantial disadvantage benchmarks.
- some algorithms rely on silent numerical overflow/underflow. if arithmetic operations checked, rewriting these algorithms become non-trivial.
- checked arithmetic not necessary ensure memory safety (as opposed other jvm checks null pointers , array bounds).
the .net virtual execution environment (now part of ecma-335 standard) introduced separate instructions checked , unchecked arithmetic, allowing independently address performance , safety concerns of developers working in modern managed languages.
Comments
Post a Comment