课程: Java Exception Handling

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Handle an ArithmeticException

Solution: Handle an ArithmeticException - Java教程

课程: Java Exception Handling

Solution: Handle an ArithmeticException

(upbeat music) - [Instructor] For your challenge you had to handle the potential ArithmeticException that could occur. Since this exception is a RuntimeException, we will not get any helpful hints from a IDE and our application will continue to build. After we see this exception for the first time we have two options, prevent the exception from occurring, through validation, or catching the exception, specifically, and handling it. We will walk through both options in this video. For the first option, which I think is more ideal, we want to validate all values involved. On line 78 we have our divisor, the number we are dividing by, defined as a variable. On the next line after this, line 79, I want to define an if statement, where if the divisor is equal to zero I want to return the String.value of zero for simplicity sake. We, of course, still have the option to return an error message to the user or some kind of other…

内容