Error handling and logging

Important

This is the Azure Sphere (Legacy) documentation. Azure Sphere (Legacy) is retiring on 27 September 2027, and users must migrate to Azure Sphere (Integrated) by this time. Use the Version selector located above the TOC to view the Azure Sphere (Integrated) documentation.

Most functions in the Azure Sphere custom application libraries (applibs) return -1 to indicate failure and zero or a positive value to indicate success. In case of failure, the function sets the value of the errno variable to the POSIX error that corresponds to the failure. Applications must include the errno.h header file, which defines this variable. The errno variable is global per thread.

Applications can log errors in the following ways:

  • During debugging, use the Log_Debug() or Log_DebugVarArgs() function to write a debug message to the Device Output window in the IDE. The format for the message is the same as that for printf.

  • During execution, send messages to an Azure IoT Hub. See Using Microsoft Azure IoT for details.