aspose file tools*
The moose likes Beginning Java and the fly likes Members accessiblity. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Members accessiblity." Watch "Members accessiblity." New topic
Author

Members accessiblity.

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
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?


Thanks,
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 350
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

Joined: Oct 30, 2007
Posts: 165
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

Joined: Aug 05, 2008
Posts: 350
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

Joined: Aug 05, 2008
Posts: 350
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Members accessiblity.