Scanner ioException() method in Java with Examples
Last Updated :
16 Oct, 2018
The ioException() method of java.util.Scanner class returns the IOException last thrown by this Scanner’s underlying Readable. This method returns null if no such exception exists.
Syntax:
public IOException ioException()
Return Value: This function returns the last exception thrown by this scanner’s readable.
Below programs illustrate the above function:
Program 1:
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "gfg geeks!" ;
Scanner scanner = new Scanner(s);
System.out.println( "" + scanner.nextLine());
System.out.println( "" + scanner.ioException());
scanner.close();
}
}
|
Program 2:
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "gopal dave!" ;
Scanner scanner = new Scanner(s);
System.out.println( "" + scanner.nextLine());
System.out.println( "" + scanner.ioException());
scanner.close();
}
}
|
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#ioException()
Share your thoughts in the comments
Please Login to comment...