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

  1. Java Tutorials:

    1. Exceptions

      1. What Is an Exception?

      2. Catching and Handling Exceptions

        1. The try Block

        2. The catch Blocks

        3. The finally Block

      3. How to Throw Exceptions

    2. Classes and Objects

      1. Understanding Class Members (static and final)

  2. Java - Built-in Exceptions

  3. Udemy

    1. Lecture 23: Static (and Final) (19:47)

    2. 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

  4. Bucky's Room

    1. 82 - Exception Handling (9:01) nextInt and division, catching all exceptions, do while to repeat

Supplemental Resources


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

  • Advantages of Exceptions

    • 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

  • Questions and Exercises

Hour 2

https://www.explainxkcd.com/wiki/index.php/1188:_Bonding