Exceptions and Error Handling

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

12 Terms

1
New cards

Exception

An event occurring during program execution that disrupts the normal flow of instructions.

2
New cards

Checked exception

A category of exceptions that the compiler mandates must either be caught or declared with the throws keyword.

3
New cards

Unchecked exception

A runtime exception that the compiler does not require you to explicitly catch or declare.

4
New cards

Handling difference between checked and unchecked exceptions

Checked exceptions require mandatory handling or declaration at compile time, whereas unchecked exceptions do not.

5
New cards

Common examples of unchecked exceptions

NullPointerException, ClassCastException, and ArithmeticException.

6
New cards

Defining a custom exception

Create a new class that extends Exception or one of its relevant subclasses.

7
New cards

throw keyword

Explicitly triggers and raises an exception from within a method or block of code.

8
New cards

throws keyword

Specifies in a method signature which exceptions the method can propagate to its caller.

9
New cards

Purpose of a try block

Encloses a segment of code that has the potential to raise an exception.

10
New cards

Purpose of a catch block

Catches and handles a matching exception thrown by an associated try block.

11
New cards

Choosing try/catch over throws

Use try/catch to resolve the problem locally; use throws to pass handling responsibility back to the caller.

12
New cards

Testing whether a method throws an exception

Execute assertThrows() by supplying the expected exception class alongside the executable code.