java中error和exception分别有几种?
来源:百度知道 编辑:UC知道 时间:2024/05/14 18:53:17
error:语法错误、逻辑错误、运行错误
exception:越界、数据丢失
//------现有资料------
java中的异常多了,但是常见的异常也就如下几种:
import java.nio.*;
import java.util.*;
class TestException {
public static void main(String[] args) {
TestException t = new TestException();
t.testIndexOutOfBoundsException();
}
// 1。ArithmeticException异常。 被除数为0时触发
public void testArithmeticException() {
int a = 10;
int b = 0;
int c = a/b;
}
// 2。ArrayStoreException异常。 数组类型不正确时触发
public void testArrayStoreException() {
Object x[] = new String[3];
x[0] = new Integer(0);
}
// 3。BufferOverflowException异常。
public void testBufferOverflowException() {
int cap = 10;
ByteBuffer bf = ByteBuffer.allocate(cap);
System.out.println(bf);
for(int i = 0;i <cap;i++) {
bf.put((byte)i);
}
System.out.println(bf);
// cause exception
一楼的这位老大你在误人子弟啊
Error 是 Throwable 的子类,用于指示合理的应用程序不应该试图捕获的严重问题。大多数这样的错误都是异常条件。虽然 ThreadDeath 错误是一个“正规”的条件,但它也是 Error 的子类,因为大多数应用程序都不应该试图捕获它。
直接已知子类:
AnnotationFormatError, AssertionError, AWTError, CoderMalfunctionError, FactoryConfigurationError, LinkageError, ThreadDeath, TransformerFactoryConfigurationError, VirtualMachineError
Exception 类及其子类是 Throwable 的一种形式,它指出了合理的应用程序想要捕获的条件。
直接已知子类:
AclNotFoundException, ActivationException, AlreadyBoundException, ApplicationException, AWTException, BackingStoreException, BadAttributeValueExpException, BadBinaryOpValueExpException, BadLocationException, BadStringOperationException, BrokenBarrierException, CertificateException, ClassNotFoundException, CloneNotSupportedException, DataFormatException, DatatypeConfigurationException, DestroyFailedException, ExecutionException, ExpandVetoException, FontFormatException, GeneralSecurityException, GSSException, IllegalAccessException, IllegalClassFormatExc