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|
|
|
|
|
|
|
|
|
public static void main(String[] args) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>throws MinusIndexException
|
|
|
|
|
{
|
|
|
|
|
int [] arr = new int[3];
|
|
|
|
|
Demo d = new Demo();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int num = d.method(arr,-27);
|
|
|
|
|
System.out.println("Hello World!"+num);
|
|
|
|
|
}
|
|
|
|
|
catch (MinusIndexException m) //<2F><><EFBFBD><EFBFBD>catch<63><68>Ҫ<EFBFBD>Ѹ<EFBFBD><D1B8><EFBFBD>exception<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
m.printStackTrace();//JVMĬ<4D>ϵ<EFBFBD><CFB5>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
System.out.println("<22>DZ겻Ϊ<EAB2BB><CEAA>");
|
|
|
|
|
//System.exit(0);//<2F>˳<EFBFBD>JVM
|
|
|
|
|
}
|
|
|
|
|
finally //ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>Դ
|
|
|
|
|
{
|
|
|
|
|
System.out.println("finally");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Demo
|
|
|
|
|
{
|
|
|
|
|
public int method (int[] arr,int index)throws MinusIndexException //<2F><><EFBFBD><EFBFBD>:
|
|
|
|
|
{
|
|
|
|
|
if (arr==null)
|
|
|
|
|
{
|
|
|
|
|
throw new NullPointerException("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>Ϊ<EFBFBD><CEAA>");
|
|
|
|
|
}
|
|
|
|
|
if (index>=arr.length)
|
|
|
|
|
{
|
|
|
|
|
throw new ArrayIndexOutOfBoundsException("<22>DZ<EFBFBD>Խ<EFBFBD><D4BD>"+index);
|
|
|
|
|
}
|
|
|
|
|
if (index<0)
|
|
|
|
|
{
|
|
|
|
|
throw new MinusIndexException();
|
|
|
|
|
}
|
|
|
|
|
return arr[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><EFBFBD>
|
|
|
|
|
<EFBFBD><EFBFBD>Ҫһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>쳣<EFBFBD>࣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳<EFBFBD><EFBFBD>쳣<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD>
|
|
|
|
|
ֻ<EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܱ<EFBFBD><EFBFBD>ؼ<EFBFBD><EFBFBD><EFBFBD>throws<EFBFBD><EFBFBD>throw<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
class MinusIndexException extends Exception
|
|
|
|
|
{
|
|
|
|
|
MinusIndexException()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
MinusIndexException(String msg)
|
|
|
|
|
{
|
|
|
|
|
super(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|