11 Exceptions, Testing, Debugging
Oracle Academy Section
Section 8: Arrays and Exceptions
Lesson 3: Exception Handling
Lesson 4: Debugging Concepts and Techniques
Section 8 Quiz
Java Foundations Certification Exam Topics
Debugging and Exception Handling
Identify syntax and logic errors
Use exception handling
Handle common exceptions thrown
Use try and catch blocks
Key Resources
Java Tutorials:
Udemy
Lecture 23: Static (and Final) (19:47)
Lecture 38: Handling Exceptions (16:23) File, hover mouse over error, adding throws to header, stack trace, read top line for information, click on last line to go to bad code, Ctrl Shift F, try catch, only goes to catch when exception, printStackTrace, code continues after catch, need static because no object of main class, catch up the stack
Bucky's Room
82 - Exception Handling (9:01) nextInt and division, catching all exceptions, do while to repeat
Supplemental Resources
Read textbook sections 7.8 and 7.9
Programmr:
Most Important Concepts / Code
The try block identifies a block of code in which an exception can occur.
The catch block identifies a block of code, known as an exception handler, that can handle a particular type of exception.
The finally block identifies a block of code that is guaranteed to execute, and is the right place to close files, recover resources, and otherwise clean up after the code enclosed in the try block.
int x1 = 0;
boolean gottenGoodInput = false;
while (gottenGoodInput == false)
{
System.out.println("Enter first number");
try {
x1 = scanner.nextInt();
gottenGoodInput = true;
}
catch (InputMismatchException ex) {
System.out.println("Requires an integer");
scanner.nextLine();
}
}
Add throws Exception at the end of a header for methods that throw exceptions but don't catch them.
Hour 1
Quiz and Concepts Review
Clear scanner with next
Separating Error-Handling Code from "Regular" Code
Propagating Errors Up the Call Stack
Grouping and Differentiating Error Types
Catching specific and general exceptions
manually throwing
Hour 2
When you get an error (red squiggly) in Eclipse.
When you get an unhandled exception in Eclipse.
Breakpoints
Error messages should be descriptive and user friendly.
Programmer Interview
Integrating exception handling in projects
Numeric input
Reading strings and converting to numbers
Dividing
https://www.explainxkcd.com/wiki/index.php/1188:_Bonding