Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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??
 
reply
    Bookmark Topic Watch Topic
  • New Topic