PrintWriter setError() method in Java with Examples
Last Updated :
31 Jan, 2019
The setError() method of PrintWriter Class in Java is used to set the error state of this PrintWriter instance. This method is used as an indicator to indicate that an error has occurred in the stream. It is protected and hence needs to be implemented by deriving the PrintWriter class to use it.
Syntax:
protected void setError()
Parameters: This method do not accepts any parameter.
Return Value: This method do not return anything.
Below methods illustrates the working of setError() method:
Program 1:
import java.io.*;
class GFG extends PrintWriter {
public GFG(OutputStream out)
{
super (System.out);
}
public static void main(String[] args)
{
String str = "GeeksForGeeks" ;
try {
GFG writer
= new GFG(System.out);
writer.write(str);
writer.flush();
writer.setError();
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Program 2:
import java.io.*;
class GFG extends PrintWriter {
public GFG(OutputStream out)
{
super (System.out);
}
public static void main(String[] args)
{
try {
GFG writer
= new GFG(System.out);
writer.write( 65 );
writer.flush();
writer.setError();
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...