Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes exceptions and interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exceptions and interfaces" Watch "exceptions and interfaces" New topic

exceptions and interfaces

Gabriel Bjorn

Joined: Dec 13, 2003
Posts: 3
Hi! I am rather new at Java, and have been reading tutorials here and there and making small programs. I am currently working on exception handling.
In one particular tutorial, I came across the next lines:

"The general form of Java's catch statement is

catch (SomeThrowableObject variableName) {
Java statements

The argument type, SomeThrowableObject, declares the type of exception that the handler can handle and must be the name of a class that inherits from the Throwable class defined in the java.lang package.
If the argument type is an interface, the exception class implements the interface."

I�m having a hard time visualizing this last bit. Can anyone give me a working example in which the argument type is an interface, and how the it works in this case?

Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
I have not used such sceniaio ever, but after thinking a lot i am trying to explain one.

Suppose your application complex architecture for exceptional handling and logging. A logger to takes argument like iMyInterface.

and i have some exceptions which has certain categories and thus have diffrent functionality for getSomeValue().

something like that:

This should give you some idea.

SCJP 5.0
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
Dear Gabriel,

No comments on my solution. Is it dificult or stupid or what??
I agree. Here's the link:
subject: exceptions and interfaces
jQuery in Action, 3rd edition