1. Learn
  2. /
  3. Courses
  4. /
  5. Data Types and Exceptions in Java

Connected

Exercise

RuntimeException

RuntimeExceptions do not require try/catch blocks in the code. They can usually be avoided with proper coding practices. However, when mistakes are not detected and the RuntimeException is uncaught, it will cause the application to fail and display issue information that the user may not always understand. In this exercise, you will see what happens when you don't catch a possible RuntimeException and what happens when you do try/catch them.

Instructions

100 XP
  • Examine the withoutTryCatch() and withTryCatch methods in this application and note the difference between them.
  • Run the application without changes - which results in the withoutTryCatch() method to execute that causes a RuntimeException.
  • Comment out line 5 and uncomment line 7, and then rerun the application, which results in the withTryCatch() method executing, which this time handles the RuntimeException.