What does it buy you What does it buy you if you throw a RuntimeException or create a subclass of RuntimeException justbecause you don't want to deal with specifying it?Simply,you get the ability to throw an exceptionwithout specifying that you do so

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 06:33:18
WhatdoesitbuyyouWhatdoesitbuyyouifyouthrowaRuntimeExceptionorcreateasubclassofRuntimeExceptionjustbe

What does it buy you What does it buy you if you throw a RuntimeException or create a subclass of RuntimeException justbecause you don't want to deal with specifying it?Simply,you get the ability to throw an exceptionwithout specifying that you do so
What does it buy you
What does it buy you if you throw a RuntimeException or create a subclass of RuntimeException just
because you don't want to deal with specifying it?Simply,you get the ability to throw an exception
without specifying that you do so.

What does it buy you What does it buy you if you throw a RuntimeException or create a subclass of RuntimeException justbecause you don't want to deal with specifying it?Simply,you get the ability to throw an exceptionwithout specifying that you do so
译文:如果你仅仅是因为不想做界定(这类情况)抛出一个运行例外,或创建一个运行例外的子类,这对你有什么好处呢?简单地说,你有能力抛出一个运行例外,但不必去界定你这样做.
相关背景知识:
Java通过面向对象的方法来处理例外(Exception).在一个方法的运行过程中,如果发生了例外,则这个方法生成代表该例外的一个对象,并把它交给运行时系统,运行时系统寻找相应的代码来处理这一例外.我们把生成例外对象并把它提交给运行时系统的过程称为抛弃(throw)一个例外.
用面向对象的方法处理例外,就必须建立类的层次.类 Throwable 位于这一类层次的最顶层,只有它的后代才可以做为一个例外被抛弃.它有两个直接子类:Error和Exception.Error类对象(如动态连接错误等),由Java虚拟机生成并抛弃(通常,Java程序不对这类例外进行处理);Exception类对象是Java程序处理或抛弃的对象.它有各种不同的子类分别对应于不同类型的例外.其中类RuntimeException代表运行时由Java虚拟机生成的例外,如算术运算例外ArithmeticException(由除0错等导致)、数组越界例外ArrayIndexOutOfBoundsException等;其它则为非运行时例外,如输入输出例外IOException等.Java编译器要求Java程序必须捕获或声明所有的非运行时例外,但对运行时例外可以不做处理.

楼上正解

是你相信、信服的意思,buy sb,相信某人,如I don't buy you.我不相信你,等于I don't believe you.

是说你买它的目的是什么,有什么用.吃不吃亏?这样子吧.