Advertisement
Checked Exceptions | Description |
---|---|
ParseException | ParseException is thrown when we try to parse a badly formatted String or when there is an error in parsing a String. |
IOException | I/O Exception is generated when we try to perform an input/output i.e. read/write operation and when the outcome is a failed or interrupted input/output operation. |
FileNotFoundException | This Exception is thrown when we are trying to access a file by specifying its path, for the purpose of reading it but this file is not found. |
ClassNotFoundException | This Exception is thrown when an our code tries to load in a class through its name but no definition for the class with the specified name could be found. |
InterruptedException | This Exception is thrown when a thread is waiting, sleeping and it has been interrupted either before or during this process. |
import java.io.*;
class CheckedEx //Class begins
{
public static void main(String... ar) //main method begins
{
File file= new File("File1.txt");
FileReader fileReader= new FileReader(file);
} //main method ends
} //class ends
D:\Java\javac CheckedEx.java
CheckedEx.java:8: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
FileReader fileReader= new FileReader(file);
^
1 error
Advertisement
import java.util.*;
import java.text.*;
class A
{
public static void main(String... ar)
{
//Converting a String to Date object.
DateFormat df = DateFormat.getInstance();
Date d= new Date(10000000000L); //creating a Date object
String str= df.format(d); //Converting Date object to String
Date d2= df.parse(str); //Converting a String to Date object.
System.out.println(d2);
}
}
A.java:14: error: unreported exception ParseException; must be caught or declared to be thrown
Date d2= df.parse(str); //Converting a String to Date object.
^
1 error
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement