Java 异常
异常架构图
The class Exception and any subclasses that are not also subclasses of RuntimeException
are checked exceptions.
RuntimeException
Java 常见 RuntimeException:
- ArithmeticException
- ClassCastException
- ConcurrentModificationException
- NullPointerException
- IndexOutOfBoundsException
Exception
- InterruptedException
- IOException
- SQLException
NoClassDefFoundError vs ClassNotFoundException
当应用程序运行的过程中尝试使用类加载器去加载 Class 文件的时候,如果没有在 classpath 中查找到指定的类,就会抛出ClassNotFoundException
。一般情况下,当我们使用 Class.forName()
或者 ClassLoader.loadClass
以及使用ClassLoader.findSystemClass()
在运行时加载类的时候,如果类没有被找到,那么就会导致 JVM 抛出ClassNotFoundException
。
NoClassDefFoundError
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.