Fandom

Programmer's Wiki

Standard error

407pages on
this wiki
Add New Page
Talk1 Share
16px-Pencil

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

2.x

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

3.x

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 = IO.new(2, "w")
errors.puts("Error goes here")

Tcl Edit

puts stderr "An error message"

External links Edit

See also Edit

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.