throw Exception | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

throw Exception

What is the difference between using throw new ArithmeticException("Division by Zero");and print ?

13th Feb 2017, 11:28 AM
dvdavid
2 Answers
+ 1
Throwing will handle the exception, "Division by Zero" is simply the message printed for the exception. Print will merely print the message, and the program will most likely crash due to the unhandled exception.
13th Feb 2017, 3:51 PM
Erik Verduin
Erik Verduin - avatar
0
And "throw" keyword is used throw an exception to the calling method where this exception can be handled using try/catch block and it is mainly used for user defined exception based on some condition where as "print" is just used to print some output or some message.
14th Feb 2017, 3:45 AM
Ratnadeep Dey
Ratnadeep Dey - avatar