aspose file tools*
The moose likes Beginning Java and the fly likes Exceptions clarification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exceptions clarification" Watch "Exceptions clarification" New topic
Author

Exceptions clarification

shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76


The above is one of the incorrect answers to a question on Exceptions. The explanation given is that in order to use the above, java.io should be imported or the exception should be declared with a fully qualified name. What is the fully qualifed name of this exception?

The entire program is as follows:

Kurt Van Etten
Ranch Hand

Joined: Sep 07, 2010
Posts: 98
Hi Shuba,

IOException is located in java.io, so the fully qualified name would be java.io.IOException (and the program will compile successfully if you make that change). That is not the only thing that is fishy with this code, though.

By the way, if you're not sure where something like this is located, you can go to the Java API docs, click on "All Classes" in the top left frame, and then scroll down the list to find the item you're looking for.
shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
Hi Kurt, thanks. I now see what that line means. The 7/x throws runtime exception. All the answer options are about declaring this exception.
David Freitag
Greenhorn

Joined: May 28, 2011
Posts: 13

There are tons of ways to work with Exceptions, and Exception types.
My favorite (And probably not the best method) is using try/catch
Example:


Generally i try to use just the simple java Exception, because it will give information about ANY Exception thrown about what you are trying to do. Further down the line your programs may need to do certain things based upon what error is thrown, that is where you would want to become more specific in what Exception you want to be looking for.

This will print to your console what exception is being thrown, from there you can do a few quick google searches to find out what the problem may be. But in this case its because you are trying to divide by zero.

if you try to run that, it will print out:
java.lang.ArithmeticException: / by zero

and a java.lang.ArithmeticException: / by zero search will give you more information on why that is bad.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884
    
  28
There is a lot in the Java™ Tutorials about Exceptions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions clarification