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 PostIn this case you are relying on the JVM to catch the exception when your main(..) method throws it, presumably because the JVM's default processing (print out the details of the Exception to System.err and terminate the program) is good enough.
In general you would put the IO method calls …
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.