As pointed out by Majenko in a comment, you can hardly define a standard
facility for error reporting when you don't know what kind of I/O
hardware will be available on any particular project. Printing to the
serial port is the most common method though, as it tends to always be
available during the development phase, while the Arduino is tethered to
the development computer. I personally tend to just do something like
Serial.println(F("Error: the warp field coil is busted."));
and be consistent with the error prefix, so that a program receiving
this can tell it's an error by matching the line against /^Error: /
.
While it is OK for user code, reporting errors through Serial
is
certainly not a good practice for library code. Alas, it is done way
too often in Arduino libraries. I've seen at least one library (don't
remember which one) that allows the user to provide a reference to a
Print
object (defaulting to Serial
) to be used for this purpose.
This is way better, as it allows the user to handle the error messages
any way she chooses. It is also very easy to turn off the error
reporting altogether by implementing a do-nothing Print
, which would
be a /dev/null
of sorts.
Note that the avr-libc allows you to print to stderr
, as long
as you have first implemented stderr->put
... While this method is the
closest you can get to the standards you are used to, it may not be
portable to non-AVR Arduinos. And it is worth noting that we tend to
avoid the printf()
family of functions on Arduinos, as they tend to be
quite large compared to the print()
and println()
methods.