Grokking Java Basics
Vote

0% completed

​

Checked vs. Unchecked Exceptions

A method named withdraw fails when an account holds too little money. This main method calls it without any exception handling:

public static void main(String[] args) { withdraw(100, 500); }

This program never starts, because the compiler stops it with the following message:

error: unreported exception InsufficientFundsException; must be caught or declared to be thrown

Now suppose that withdraw throws IllegalArgumentException instead. The same main method compiles, and the program stops only when it runs

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content