i read that a method that is is using throws clause must be mentioned in the try and catch block.So when we use "throws IOException" in the following program why dont we use try and catch
import java.io.*;
class testthrows
{
public static void main(String args[]) //throws IOException
{
int i;
System.out.println("enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
i=Integer.parseInt(br.readLine());
System.out.println(i);
}
}
why dont we use try and catch here
akulkarni
0
Junior Poster
Recommended Answers
Jump to PostA try catch block is necessary if you want to handle the exception. If you don't want to handle the exception, you can announce the fact through a throws clause appended to the method. The calling method then has to take care or pass it up the hierarchy. In your …
All 4 Replies
deepak.marur
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
akulkarni
0
Junior Poster
akulkarni
0
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.