Presentation 7
Presentation 7
Object
Oriented
Programming
Dr. Abdulaziz Saleh Algablan
Email: [email protected]
2023
Topics
Exception Handling
What is the Problem ?
a) public static int divide( int a, int b )
{
try{
return a / b;
}
catch() {}
}
b) public static void getUserInput()
{
// declaration of scanner.
// some code
int age = scanner.nextInt();
scanner.next();
}
What is the Problem ?
• For (a), if the following is entered:
• a = 100
• b =0
• Exception in thread "main" java.lang.ArithmeticException: / by zero