i have a problem and i would like to knwo if some one can explain the directions in a simpler form because i have no idea what i am really supposed to do like how many classes i need if i need any and what should go in main. the problem as follows. i dont want any one to write the program i know the rules i just looking for direction.

1. Write a program that calls a method from main() which throws an exception of type ArithmeticException at a random iteration in a for loop. Catch the exception in the method, and pass the iteration count when the exception occurred to the calling method, main(), by using an object of an exception class you define yourself. Then, add finally block to the method to output the iteration count when the method exits.

9 Years
Discussion Span
Last Post by alpha_foobar

What specifically would you like to know about this problem?

An ArithmeticException is thrown when something involving arithmetic occurs that is not handled by the Java language. The example in the Java API is an integer divide by zero exception.

So you need to create a situation where this situation will occur. i.e. x/0. The question implies this should be in a for loop (at any time), the for loop should be inside a method.

The question seems to be poorly worded, but it reads to me that the method should catch the arithmetic exception and know which iteration it was thrown. This information should be returned to main, but in a new Exception instance. The question seems to state that the exception should be a class created by you and should hold an int.

Actually I could say exactly what you are supposed to do from that question - is that how it is exactly worded? It seems to ask that you catch the exception you created in the method with the for loop, and have a finally block that outputs the value of the iteration? Perhaps it means this should be done in the main method?

I can say you need two classes, an exception class and an application class. I can also say you will get close to full marks if you implement everything mentioned.. even if it perhaps isn't in the exact place the tutor intended, what is more important is an understanding of syntax and language implementation rather than an exact implementation of a tutorial...

though there are some exceptions - I have been in classes where you could not pass a lab without creating perfect output, some even had execution time limitations, the class seemed to be based around ACM programming competition questions. To be honest some of this was enjoyable, but honestly most of it was a waste of time and many of my class dropped out or failed. Happily there are not many classes that require this degree of accuracy.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.