package com.jarvis.java.exception;
import java.io.IOException;
/**
* @author jinzhaopo
* @date 2024-01-18 15:45
*/
public class SimpleException {
public static void main(String[] args) {
//testRuntimeException(0);
testRuntimeException(1);
try {
//testCheckedException(0);
testCheckedException(1);
testError(0);
} catch (Error e) {
// error是一种系统级别的问题,一般不需要显示的捕获和处理
System.out.println("method test error");
} catch (IOException e) {
System.out.println("method test exception");
}
}
public static void testCheckedException(int i) throws IOException {
if (i == 0) {
throw new IOException();
}
}
public static void testRuntimeException(int i) {
if (i == 0) {
throw new RuntimeException();
}
}
public static void testError(int i) {
if (i == 0) {
throw new OutOfMemoryError();
}
}
}