I am getting unexpected output,how come "trying to divide by zero " is not displayed?,When I divide by 0 I get to the catch block with throws ("trying to divide by zero") but when I come back to my main method I would expect that first it would throw that error in the divide method and not in the main method's catch block.
When you divide by zero in the divide() method, that division causes an ArithmeticException to be thrown, which the divide() method explicitly catches.
You then throw a new ArithmeticException with the text "trying to divide by 0".
The main() method catches that exception. In the catch-clause you ignore that exception and print "did not work".
Your exception is caught right where it is supposed to be caught in the divide method, but all you do is immediately throw it again, so of course it's going to be caught at the previous level's exception handler. Do something in your catch before you rethrow the exception and you'll see you actually enter that catch block in the divide method.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH