Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me code the following in JAVA 2. Handling exceptions a. b. c. d. Dow

ID: 3714091 • Letter: P

Question

Please help me code the following in JAVA

2. Handling exceptions a. b. c. d. Download the following file from the class website: CallStack.java Examine the code to determine what it does. Compile and execute the code. Modify the main0 method to handle the exception that is propagated to it. Use a try- catch block to display a meaningful error message when the exception occurs. Test your code. Notice that, although the exception was thrown in func2, it is caught by the catch block in the main method. e.

Explanation / Answer

public class CallStack {
void func2() {
System.out.println("In func2 method");
int a = 0;
int b;
b=10/a;
}
void func1() {
System.out.println("In func1 method");
this.func2();
System.out.println("Back In func1 method");
}
public static void main(String args[]) {
CallStack myCallStack;
myCallStack =new CallStack();
System.out.println("In main method");
try {
myCallStack.func1();
}catch(ArithmeticException e) {
System.out.println("Exception Occurred. Divisor can not be zero");
}

}
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote