/**
* <p>TestException.java </p>
*
* <p>异常的测试: </p>
*
* @author not attributable
* @version 1.0
*/
//部门的异常
class ExcpDe extends Exception{
ExcpDe()
{
super("部门不存在");
}
}
//姓名异常
class ExcpName extends Exception{
ExcpName()
{
super("姓名应为字符");
}
}
//
class TestException{
public static void main(String[] mystr) {
try{
for(int i = 0; i < mystr[0].length();i++)
{
if(Character.isDigit(mystr[0].charAt(i)))
{
throw new ExcpName();
}
}
Integer.parseInt(mystr[1]);
if (Integer.parseInt(mystr[2]) > 5)
{
throw new ExcpDe();
}
System.out.println("姓名:"+mystr[0]);
System.out.println("员工编号:"+mystr[1]);
System.out.println("部门编号:"+mystr[2]);
}catch (NumberFormatException e){
System.out.println("Exception in classTestException in method main:"+e.toString());
e.printStackTrace();
} catch (ExcpDe ex){
System.out.println("Exception in classTestException in method main:"+ex.toString());
ex.printStackTrace();
return;
}catch(ExcpName en){
System.out.println("Exception in classTestException in method main:"+en.toString());
en.printStackTrace();
return;
}catch(Exception ee)
{
System.out.println("Exception in classTestException in method main:"+ee.toString());
ee.printStackTrace();
return;
}
finally
{
System.out.println("finally 的执行情况是除非用了System.exit(1)外都会被执行");
}
}
}