Formatter ioException() method in Java with Examples Last Updated : 01 Apr, 2019 Comments Improve Suggest changes Like Article Like Report The ioException() method is a built-in method of the java.util.Formatter which returns the IOException last thrown by this formatter's Appendable. If the destination's append() method never throws IOException, then this method will always return null. Syntax: public IOException ioException() Parameters: The function accepts no parameter. Return Value: The function returns the IOException which was last thrown by the Formatter's appendable. Below is the implementation of the above function: Program 1: Java // Java program to implement // the above function import java.util.Formatter; import java.util.Locale; public class Main { public static void main(String[] args) { // Get the string Buffer StringBuffer buffer = new StringBuffer(); // Object creation Formatter frmt = new Formatter(buffer, Locale.CANADA); // Format a new string String name = "My name is Gopal Dave"; frmt.format("What is your name? \n%s !", name); // Print the Formatted string System.out.println(frmt); // flushes the formatter frmt.flush(); System.out.println("Flushed"); } } Output: What is your name? My name is Gopal Dave ! Flushed Program 2: Java // Java program to implement // the above function import java.util.Formatter; import java.util.Locale; public class Main { public static void main(String[] args) { // Get the string Buffer StringBuffer buffer = new StringBuffer(); // Object creation Formatter frmt = new Formatter(buffer, Locale.CANADA); // Format a new string String name = "My name is Gopal Dave"; frmt.format("What is your name? \n%s !", name); System.out.println("The last exception thrown: " + frmt.ioException()); // Closes the format frmt.close(); } } Output: The last exception thrown: null Output: The last exception thrown: null Reference: https://docs.oracle.com/javase/10/docs/api/java/util/Formatter.html#flush() Comment More infoAdvertise with us Next Article Formatter ioException() method in Java with Examples G gopaldave Follow Improve Article Tags : Java Java - util package Java-Functions Java-Formatter Practice Tags : Java Similar Reads Formatter out() method in Java with Examples The out() method is a built-in method of the java.util.Formatter which returns the destination for the output by the formatter. Syntax: public Appendable out() Parameters: The function accepts no parameter. Return Value: The function returns the destination for the output. Exceptions: The function t 2 min read Scanner ioException() method in Java with Examples 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' 2 min read Top 5 Exceptions in Java with Examples An unexpected unwanted event that disturbs the program's normal execution after getting compiled while running is called an exception. In order to deal with such abrupt execution of the program, exception handling is the expected termination of the program. Illustration: Considering a real-life exa 5 min read Constructor getGenericExceptionTypes() method in Java with Examples The getGenericExceptionTypes() method of java.lang.reflect.Constructor class is used to return the exception types present on this constructor object as an array. The returned array of objects represent the exceptions declared to be thrown by this constructor object. If this constructor declares no 2 min read Types of Exception in Java with Examples Java defines several types of exceptions that relate to its various class libraries. Java also allows users to define their own exceptions. Built-in Exceptions: Built-in exceptions are the exceptions that are available in Java libraries. These exceptions are suitable to explain certain error situati 8 min read Like