Page 1 of 1

## 2 Replies - 2342 Views - Last Post: 26 November 2011 - 04:24 AM

### #1 William_Wilson

• lost in compilation

Reputation: 207
• Posts: 4,812
• Joined: 23-December 05

Posted 05 May 2006 - 08:50 AM

Description: This example uses a divide by zero Exception. including a tester class to demonstrate the throwing.extending class Exception to generate your own output messages
```Exception Class DivideByZeroException
[code]
public class DivideByZeroException extends ArithmeticException {
public DivideByZeroException() {
super("Attempted to divide by zero!");
}
}

```
Tester Class ExceptionTester
```public class ExceptionTester {
private static int quotient(int numerator, int denominator) throws DivideByZeroException {
if(denominator == 0)
throw new DivideByZeroException();
return(numerator / denominator);
}

public static void main(String args[]) {
int number1=0, number2=0, result=0;
try {
number1 = 1;
number2 = 0;
result = quotient(number1,number2);
System.out.print(number2 + " goes into " + number1);
System.out.println(" this many times: " + result);
}
catch (Exception e) {
System.out.println(e.toString());
System.out.println("An Exception occured");
System.exit(-1);
}
}
}

```
[/code]

Is This A Good Question/Topic? 0

## Replies To: Write Your Own Exceptions

### #2 Suffiyanish

Reputation: 0
• Posts: 2
• Joined: 25-November 11

## Re: Write Your Own Exceptions

Posted 26 November 2011 - 04:24 AM

i wonna know how to make runtimeexception.....

### #3 Suffiyanish

Reputation: 0
• Posts: 2
• Joined: 25-November 11

## Re: Write Your Own Exceptions

Posted 26 November 2011 - 04:24 AM

i wonna know how to make runtimeexception.....