• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exceptions and interfaces

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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-
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Gabriel,

No comments on my solution. Is it dificult or stupid or what??
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic