answersLogoWhite

0

// A method which throws an exception.

// Declare an ArithmeticException to be thrown.

int integerDivision(int a, int b) throws ArithmeticException {

// If we try to divide by zero, throw our exception...

if(b == 0) {

throw new ArithmeticException("Division by 0");

}

// ...otherwise, return our result.

return a/b;

}

// A method which catches an exception.

void doSomeDivision() {

// Let's divide each integer [0,9] by one another...

for(int a = 0; a < 10; ++a) {

for(int b = 0; b < 10; ++b) {

// Try to do the division...

try {

final int q = integerDivision(a,b);

System.out.println(a + " / " + b + " = " + q);

} catch(ArithmeticException ex) {

// ...end up here in case of Exception

System.out.println("Cannot divide " + a + " by " + b);

}

}

}

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Can you give an example of a sentence using word get through?

I had to get through the hedge to reach my house. (Just an example)


Concept of MBE in management?

management by exception .it give exception for some cases


Give me an example of Preposition of direction?

Ex: through, across, along, etc.


Do sheeps lay eggs?

Sheep are mammals and mammals do not lay eggs with one exception, the monotremes, of which the Platypus is an example.


Can you give me one example using a sentencewith an wade?

They waded through the river to get to their school. This is an example of word using wade.


Can you give me an example of a sentence using the word serpent?

The serpent slithered through the grass.


Who can benefit from debt consolidation programs?

Many people benefit from debt consolidation programs. For example, it will give you more control in paying off your debt. Furthermore, people whom you owe money to will receive their payment.


Give example of sentence with the word thrashing?

I dont want my computer to go through thrashing.


What is exception and give a simple example in java programming?

Exception is a situation in Java wherein the system is behaving in a not-so-correct way or rather the system is behaving in an erroneous way. Exceptions are handled using try-catch blocks. Ex: try { int x = 10/0; } catch (Exception e) { e.printStackTrace(); } Here we are performing an illegal operation by dividing 10/0 which will throw a numeric exception which will be caught and handled inside the catch block


They would like to get some information on becoming a physical therapist, through online education.?

A simple online search for physical therapy programs will give you a list of programs. You want to make sure you look for an accredited program.


What programs can give an analysis of spending habits?

There are a few different options for programs that will give an analysis of spending habits. Some of the programs that provide analysis are Quicken and The Birdy web application.


What is transparent opaque?

opaque transparency is when you can see through it but its all blurry