Java Exception

Java Exception

What Is an Exception?

The term exception is shorthand for the phrase “exceptional event.”

Definition: An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions.
定义:异常是一个发生在程序执行期间的事件,它破坏了程序指令的正常流程。

When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.
当方法中出现错误时,方法将会创建一个对象,然后把它交给运行时系统。这个对象被称之为异常对象,它携带了关于这个错误的信息,包括错误类型以及程序出错时的状态。创建异常对象并把它交给运行时系统就叫做抛出异常。

After a method throws an exception, the runtime system attempts to find something to handle it. The set of possible “somethings” to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the call stack (see the next figure).
方法抛出异常后,运行时系统将尝试去找到“something”来处理这个异常。一系列可能的处理异常的“something”就是一个有序的、已被调用的方法列表,方法列表终止于错误出现处。这个方法列表通常被熟知为调用栈。

这里写图片描述

The runtime system searches the call stack for a method that contains a block of code that can handle the exception. This block of code is called an exception handler. The search begins with the method in which the error occurred and proceeds through the call stack in the reverse order in which the methods were called. When an appropriate handler is found, the runtime system passes the exception to the handler. An exception handler is considered appropriate if the type of the exception object thrown matches the type that can be handled by the handler.
运行时系统检索调用栈来寻找一个含有处理该异常的代码块的方法,该代码块也被称之为异常处理器。检索过程开始于错误发生的地方,反向搜索整个调用栈,当找到对应的处理器时,运行时系统将会把异常传递给该处理器。处理器被认为是对应的意味着抛出的异常类型匹配了该处理器所能处理的异常类型。

The exception handler chosen is said to catch the exception. If the runtime system exhaustively searches all the methods on the call stack without finding an appropriate exception handler, as shown in the next figure, the runtime system (and, consequently, the program) terminates.
异常处理器选择也被叫做捕获异常,如果运行时系统搜尽所有调用栈方法却没有找到合适的异常处理器,如下图所示,运行时系统(程序)将会终止。

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值