printerr function

void printerr(
  1. String? line
)

Write a message to stderr (standard error output).

This function provides the equivalent functionality to Dart's standard print function, but writes to stderr instead of stdout. This follows CLI conventions where error messages should go to stderr.

Parameters:

  • line: The message to write to stderr (null is converted to 'null')

This function cooperates with zone-based output capture if configured. When running in a zone with capturePrinterrKey set, the output will be redirected to the configured capture function.

Example:

// Write error message to stderr
printerr('Error: File not found');

// Write warning to stderr
printerr('Warning: Deprecated function used');

// Handle null values gracefully
String? message = null;
printerr(message); // Outputs 'null'

See also:

Implementation

void printerr(String? line) {
  /// Co-operate with runDCliZone
  final overloaded = Zone.current[capturePrinterrKey] as CaptureZonePrintErr?;
  if (overloaded != null) {
    overloaded(line);
  } else {
    stderr.writeln(line);
  }
}