Question: 1 . Create Java project Week 0 3 Exceptions. Create TestExceptions.java to demonstrate exceptions in Java. 2 . TestExceptions.java must have the following methods: main,
Create Java project WeekExceptions. Create TestExceptions.java to demonstrate exceptions in Java.
TestExceptions.java must have the following methods: main, TestArithmeticError, TestArrayIndexError, TestNumbeFormatError, TestStringIndexError, and TestNullPointerError. points
a main: This calls other methods.
b TestArithmeticError: Test dividing a number by zero. Initialize intNum and intNum respectively to and zero. Declare output to be equal to intNum intNum Catch division by zero and display message You should not divide a number by zero
c TestArrayIndexError: Test accessing an array index which does not exist. For example, if an array has only elements and we are trying to display th element then it would throw this exception. The exception message should display Array Index Out of Bounds
d TestNumberFormatError: Test parsing a string to any numeric variable using Integer.parseInt. It will throw NumberFormatException since a string cannot be parsed to int. Display exception message Number format exception occurred
e TestStringIndexError: Test for an index that is not within the range. Each character of a string object is stored in a particular index starting from Use method charAtintIndex of java.lang.String where intIndex argument is the index. Display exception message String Index Out of Bound Exceptions
f TestNullPointerError: Test for a null object using strlength. Display exception message Null Pointer Exception
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
