dcsimg
how to write a class that need catch?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   lai_seong
Posted On:   Sunday, February 20, 2005 06:37 AM

How can i write my own class that need the certain catch in order for other programmer to use my class? Like following.It can not be run without the catch
(FileNotFoundException e){}.




try

{

BufferedReader readFile= new BufferedReader(new FileReader(infTempFile));

}catch(FileNotFoundException e){}

Re: how to write a class that need catch?

Posted By:   Christopher_Koenigsberg  
Posted On:   Sunday, February 20, 2005 06:51 AM

Either you add your "throws" for a checked exception, or you just fail to catch one that is thrown by a method you call.


Is this what you mean? but this is so basic, are you asking something else? because even in the example you gave, the caller can catch a more general parent type, on up to Throwable even, rather than the specific type of checked exception you throw.


And if you throw a subclass of RuntimeException rather than of Exception, the caller does not have to catch it, because that's "unchecked". but there is a movement nowadays to prefer using unchecked rather than checked exceptions.
About | Sitemap | Contact