user59545: I'm new to Arduino but I'm an experienced programmer. I'm wondering if there are any common functions for reporting errors in Arduino programs? For example, in JavaScript we have the alert() function, or on Unix you can write a message to standard error and exit.
Ideally, if the serial port is available then an error message would be printed there, or if there is an LED then maybe we should blink it. This would need to be configurable based on what the programmer wants to do with available hardware.
Looking the example sketches, error reporting seems pretty horrible. I'm wondering if any libraries handle this better?

user7508: 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.

59545: <p>I'm new to Arduino but I'm an experienced programmer. I'm wondering if there are any common functions for reporting errors in Arduino programs? For example, in JavaScript we have the alert() function, or on Unix you can write a message to standard error and exit.</p>

<p>Ideally, if the serial port is available then an error message would be printed there, or if there is an LED then maybe we should blink it. This would need to be configurable based on what the programmer wants to do with available hardware.</p>

<p>Looking the example sketches, error reporting seems pretty horrible. I'm wondering if any libraries handle this better?</p>
 7508: <p>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</p>

<pre class="lang-cpp prettyprint-override"><code>Serial.println(F("Error: the warp field coil is busted."));
</code></pre>

<p>and be consistent with the error prefix, so that a program receiving
this can tell it's an error by matching the line against <code>/^Error: /</code>.</p>

<p>While it is OK for user code, reporting errors through <code>Serial</code> is
certainly <em>not</em> 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
<code>Print</code> object (defaulting to <code>Serial</code>) 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 <code>Print</code>, which would
be a <code>/dev/null</code> of sorts.</p>

<p>Note that the avr-libc <a href="https://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html" rel="nofollow noreferrer">allows you to print to <code>stderr</code></a>, as long
as you have first implemented <code>stderr-&gt;put</code>... 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 <code>printf()</code> family of functions on Arduinos, as they tend to be
quite large compared to the <code>print()</code> and <code>println()</code> methods.</p>
