|
|
Исходный текст программы exept.java
|
Оглавление |
Назад
// =======================================
// exept.java
//
// (C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// =======================================
public class exept
{
public static void main(String args[])
{
// --------------------------------------
// ArrayIndexOutOfBoundsException
// --------------------------------------
System.out.println(
"* ArrayIndexOutOfBoundsException *\n");
int i = 0;
int[] nArray = new int[5];
while(true)
{
try
{
nArray[i] = i;
}
catch(Exception ex)
{
System.out.println("\n" +
ex.toString());
break;
}
System.out.print(i);
i++;
}
// --------------------------------------
// ArithmeticException
// --------------------------------------
System.out.println(
"\n* ArithmeticException *\n");
i = 0;
try
{
i = 5/i;
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
// --------------------------------------
// ArrayStoreException
// --------------------------------------
System.out.println(
"\n* ArrayStoreException *\n");
Object szStr[] = new String[10];
try
{
szStr[0] = new Character('*');
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
// --------------------------------------
// ClassCastException
// --------------------------------------
System.out.println(
"\n* ClassCastException *\n");
Object ch = new Character('*');
try
{
System.out.println((Byte)ch);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
// --------------------------------------
// NegativeArraySizeException
// --------------------------------------
System.out.println(
"\n* NegativeArraySizeException *\n");
try
{
int[] nNegArray = new int[-5];
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
// --------------------------------------
// NullPointerException
// --------------------------------------
System.out.println(
"\n* NullPointerException *\n");
int[] nNulArray = new int[5];
nNulArray = null;
try
{
i = nNulArray.length;
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
// --------------------------------------
// StringIndexOutOfBoundsException
// --------------------------------------
System.out.println(
"\n* StringIndexOutOfBoundsException *\n");
String szShortString = "123";
try
{
char chr = szShortString.charAt(10);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
}
Назад |
|
|