Standard error is an standard output stream where a program may write its error messages.

The following snippets show how to do this using various languages.

Snippets Edit

C Edit

#include <stdio.h>

fprintf(stderr, "something broke :-(\n");

C++ Edit

#include <iostream>

std::cerr << "something broke :-(" << std::endl;

C# Edit

System.Console.Error.WriteLine("something broke :-(");

Java Edit

System.err.println("something broke :-(");

OCaml Edit

prerr_endline "something broke :-(";
Printf.eprintf "something broke :-(\n";

Perl Edit

print STDERR "something broke :-(\n";

PHP Edit

When using PHP in CLI mode (Command Line Interface), you can send error messages to stderr:

fputs(STDERR, 'Error!'); // sends 'Error!' to stderr

Under a webserver, the STDERR stream is usually linked to the web server's error log.

Python Edit


import sys
print >> sys.stderr, "something broke :-("
sys.stderr.write("something broke :-(") # no trailing newline


import sys
print("something broke :-(", file=sys.stderr)

Ruby Edit

To just write to standard error:

$stderr.puts("Error goes here")

If you want to create an IO object and point that to standard error:

# the file descriptor 2 = standard error
errors =, "w")
errors.puts("Error goes here")

Tcl Edit

puts stderr "An error message"

External links Edit

See also Edit