package frank;
import java.lang.*;
/**
* java异常处理,当程序运行时发生错误的时候就会找是否定义了适合的catch块,如果有就把异常对象交给catch快出处理,如果没有程序就会退出。
* 进行异常捕获的时候先捕捉小异常,然后在捕捉大异常。
* */
public class App<S>
{
public static void main(String[] args)throws Exception
{
/* 单个catch块
System.out.println(args);
try
{
String s = args[1];
}
catch (Exception e)
{
System.out.println("1sa"+e);
}*/
/*
try
{
String str1 = args[1];
int b = Integer.parseInt(str1);
int a = Integer.parseInt(args[0]);
int c = a /b;
}
catch (IndexOutOfBoundsException ie)
{
System.out.println("数组索引越界!");
}
catch (NumberFormatException ne)
{
System.out.println("数字格式化错误!");
}
catch (ArithmeticException ae)
{
System.out.println("除数不能为0!");
}
catch (Exception e)
{
System.out.println("未知异常!");
}*/
/**JAVA 7 里面catch块可以 捕获多个异常,多个用|隔开,异常对象用隐士的final修饰的,不能对它进行重新赋值**/
/*
try
{
String str1 = args[1];
int b = Integer.parseInt(str1);
int a = Integer.parseInt(args[0]);
int c = a /b;
}
catch (IndexOutOfBoundsException|NumberFormatException e)
{
System.out.println("数组越界,数字格式化错误!");
//e = new NumberFormatException("test");//异常
}
catch(Exception e)
{
}*/
/**获得异常信息及输出异常跟踪信息*/
try
{
String str1 = args[1];
int b = Integer.parseInt(str1);
int a = Integer.parseInt(args[0]);
int c = a /b;
}
catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}