Fork of the official mbed C/C++ SDK provides the software platform and libraries to build your applications. The fork has the documentation converted to Doxygen format

Dependents:   NervousPuppySprintOne NervousPuppySprint2602 Robot WarehouseBot1 ... more

Fork of mbed by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers error.h Source File

error.h

00001 /* mbed Microcontroller Library - error
00002  * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
00003  */ 
00004  
00005 #ifndef MBED_ERROR_H
00006 #define MBED_ERROR_H
00007 
00008 /** To generate a fatal compile-time error, you can use the pre-processor #error directive.
00009  *
00010  * @code
00011  * #error "That shouldn't have happened!"
00012  * @endcode
00013  *
00014  * If the compiler evaluates this line, it will report the error and stop the compile.
00015  *
00016  * For example, you could use this to check some user-defined compile-time variables:
00017  * 
00018  * @code
00019  * #define NUM_PORTS 7
00020  * #if (NUM_PORTS > 4)
00021  *     #error "NUM_PORTS must be less than 4"
00022  * #endif
00023  * @endcode
00024  *
00025  * Reporting Run-Time Errors:
00026  * To generate a fatal run-time error, you can use the mbed error() function.
00027  *
00028  * @code
00029  * error("That shouldn't have happened!");
00030  * @endcode
00031  *
00032  * If the mbed running the program executes this function, it will print the 
00033  * message via the USB serial port, and then die with the blue lights of death!
00034  *
00035  * The message can use printf-style formatting, so you can report variables in the 
00036  * message too. For example, you could use this to check a run-time condition:
00037  * 
00038  * @code
00039  * if(x >= 5) {
00040  *     error("expected x to be less than 5, but got %d", x);
00041  * }
00042  * #endcode
00043  */
00044  
00045 #if 0 // for documentation only
00046 /** Report a fatal runtime error
00047  *
00048  *  Outputs the specified error message to stderr so it will appear via the USB 
00049  *  serial port, and then calls exit(1) to die with the blue lights of death.
00050  *
00051  *  @param format printf-style format string, followed by associated variables
00052  */
00053 void error(const char* format, ...);
00054 #endif  
00055 
00056 #include <stdlib.h>
00057 
00058 #ifdef NDEBUG
00059     #define error(...) (exit(1))
00060 #else
00061     #include <stdio.h>
00062     #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
00063 #endif
00064 
00065 #endif