Java System err Field
Example
Print an error message with System.err:
public class Main {
public static void main(String[] args) {
int age = -5;
if (age < 0) {
System.err.println("Error: the age cannot be negative.");
}
}
}
Definition and Usage
The System.err field is the standard error stream. Use it to print error messages.
The text is shown in the console, like text from System.out. But the two streams are separate, so errors can be sent to another place, like a log file. Some editors show the error text in red.
Tip: Use System.out to print normal output.
Syntax
public static final PrintStream err
Related Pages
❮ System Methods