问题描述
Java中是否有RuntimeException异常发生的可能性?谢谢。
java.lang包定义了以下不是运行时异常的标准异常类:
-
:抛出异常,表示无法找到要加载的类。
$ b > CloneNotSupportedException :当为没有实现Cloneable接口的对象调用clone()方法,因此无法克隆时,会抛出此异常。 $ b >异常 :此异常的适当子类在respo中抛出在虚拟机级别检测到错误。如果一个程序定义了自己的异常类,它们应该是Exception类的子类。 -
:当程序尝试动态加载时抛出此异常一个类(即使用Class类的forName()方法,或者ClassLoader类的findSystemClass()或loadClass()方法),并且当前执行的方法无法访问指定的类,因为它在另一个包,而不是公开。当一个程序尝试创建一个类的实例(即使用Class类的newInstance()方法)时,这个异常也被抛出,它没有调用者可以访问的零参数构造函数。
-
:这个异常是为了响应使用Class类的newInstance()方法来实例化一个抽象类或一个接口而引起的。
-
:抛出异常,表示正在睡眠,等待或暂停的线程已被另一个线程中断。
-
:当找不到指定的变量时,抛出此异常。这个例外是Java 1.1中的新例。
-
:当找不到指定的方法时,抛出此异常。
Is there any possibility of exceptions to occur other than RuntimeException in Java? Thanks.
The java.lang package defines the following standard exception classes that are not runtime exceptions:
ClassNotFoundException: This exception is thrown to indicate that a class that is to be loaded cannot be found.
CloneNotSupportedException: This exception is thrown when the clone() method has been called for an object that does not implement the Cloneable interface and thus cannot be cloned.
Exception: The appropriate subclass of this exception is thrown in response to an error detected at the virtual machine level. If a program defines its own exception classes, they should be subclasses of the Exception class.
IllegalAccessException: This exception is thrown when a program tries to dynamically load a class (i.e., uses the forName() method of the Class class, or the findSystemClass() or the loadClass() method of the ClassLoader class) and the currently executing method does not have access to the specified class because it is in another package and not public. This exception is also thrown when a program tries to create an instance of a class (i.e., uses the newInstance() method of the Class class) that does not have a zero-argument constructor accessible to the caller.
InstantiationException: This exception is thrown in response to an attempt to instantiate an abstract class or an interface using the newInstance() method of the Class class.
InterruptedException: This exception is thrown to signal that a thread that is sleeping, waiting, or otherwise paused has been interrupted by another thread.
NoSuchFieldException: This exception is thrown when a specified variable cannot be found. This exception is new in Java 1.1.
NoSuchMethodException: This exception is thrown when a specified method cannot be found.
这篇关于异常除了RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!