0

For example in number divide by zero how try block identify that at what statement it has to throw the exception. does it check the denominator value implicitly and it does than how it knows

1
  • Are you asking about classic java try{} catch{} block ?? Commented Feb 8, 2020 at 16:35

1 Answer 1

1

Exceptions don't work that way.

The try{} catch {} blocks doesn't know anything, as it is not the one throwing an exception, it is just there on how to handle an exception thrown by code inside the try block.

In your case, ArithmeticException is thrown at runtime by the VM when the denominator is 0, after that the stacktrace is populated as in case of any exception.

ArithmeticException is thrown when an exceptional arithmetic condition has occurred. For example, an integer "divide by zero" throws an instance of this class. ArithmeticException objects may be constructed by the virtual machine as if suppression were disabled and/or the stack trace was not writable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.