1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
|
class Exceptions
{
int zaehler = 5;
int nenner = 0;
public void nuller (int nenner) throws IllegalAccessException
{
int result = zaehler/nenner;
if (nenner==0)
{
throw new IllegalAccessException("Nenner ist gleich 0");
}
System.out.println(result);
}
}
public class Methodentest
{
public static void main (String[]args)
{
try
{
nenner(-1);
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
} |