Summary

Today you learned about how exceptions aid your program's design and robustness. Exceptions give you a way of managing potential errors in your programs and of alerting your programs'users that potential errors can occur. By using try, catch, and finally, you can protect code that might result in exceptions, catch and handle those exceptions if they occur, and execute code whether an exception was generated or not.

Handling exceptions is only half of the equation; the other half is generating and throwing exceptions yourself. Today you learned about the throws clause, which tells your method's users that the method might throw an exception. throws can also be used to pass on an exception from a method call in the body of your method.

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.