Win a copy of Microservices Testing (Live Project) 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

Members accessiblity.

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Difference between throw and throws clause?
Using throw clause we define the exception explicitly then when to use the throws clause?
What hidden members refer to?Are they members with private accessibility?If not what is the difference?
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
with throw you throw Exceptions.

i.e.
throw new NullPointerException();
throw new Exception();

you use throws in a method/constructor declaration to indicate that same may throw an Exception.

like..

public void doWork() throws SomeException
{
//within this method SomeException should be thrown
}

Static members are said to be hidden in a subclass rather than being overidden. Check here and herefor an explanation.
 
Phillipe Rodrigues
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,throws clause are declared with the method prototype with an assumtion that the method should throw the exception(or its subclass) that is defined after throws clause.

where and how the exception is handled?
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any method calling a method that throws an Exception should either be enclosed in
a try block with one or more catch and optionally finally block OR the
calling method should throw the Exception (or a Throwable superclass of
that Exception ).
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be you are asking how best Exceptions should be handled?

There are a number of views on how best to handle Checked Exceptions.

During the compilation compiler will complain of any uncaught of unthrown exceptions. Then you could catch the Exception immediately and take corrective action. (e.g. You are trying to open a file and FileNotFoundException is thrown. You catch it and in the catch block you create the missing file and continue with the program).

This is one approach.here and here are a couple of links to get a feeling of this subject.
reply
    Bookmark Topic Watch Topic
  • New Topic