Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exceptions and interfaces

 
Gabriel Bjorn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks-
 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Gabriel,

No comments on my solution. Is it dificult or stupid or what??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic