Documentation

The Java™ Tutorials
Hide TOC
Exceptions异常
Trail: Essential Java Classes

Lesson: Exceptions教训:例外

The Java programming language uses exceptions to handle errors and other exceptional events.Java编程语言使用异常来处理错误和其他异常事件。This lesson describes when and how to use exceptions.本课程介绍何时以及如何使用异常。

What Is an Exception?什么是异常?

An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.异常是在程序执行过程中发生的事件,它会中断正常的指令流。

The Catch or Specify Requirement捕获或指定要求

This section covers how to catch and handle exceptions.本节介绍如何捕获和处理异常。The discussion includes the try, catch, and finally blocks, as well as chained exceptions and logging.讨论包括trycatchfinally块,以及链接异常和日志记录。

How to Throw Exceptions如何抛出异常

This section covers the throw statement and the Throwable class and its subclasses.本节介绍throw语句和Throwable类及其子类。

The try-with-resources Statementtry-with-resources语句

This section describes the try-with-resources statement, which is a try statement that declares one or more resources.本节介绍try-with-resources语句,它是一个try语句,用于声明一个或多个资源。A resource is as an object that must be closed after the program is finished with it.资源是一个对象,必须在程序完成后关闭。The try-with-resources statement ensures that each resource is closed at the end of the statement.try-with-resources语句确保在语句末尾关闭每个资源。

Unchecked Exceptions — The Controversy未经检查的异常—争论

This section explains the correct and incorrect use of the unchecked exceptions indicated by subclasses of RuntimeException.本节解释RuntimeException子类指示的未检查异常的正确和错误使用。

Advantages of Exceptions例外的好处

The use of exceptions to manage errors has some advantages over traditional error-management techniques.与传统的错误管理技术相比,使用异常管理错误具有一些优势。You'll learn more in this section.您将在本节了解更多信息。

Summary小结

Questions and Exercises问题和练习


Previous page: Table of Contents
Next page: What Is an Exception?