1 /* mbed Microcontroller Library 2 * Copyright (c) 2006-2013 ARM Limited 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MBED_ERROR_H 17 #define MBED_ERROR_H 18 19 /** To generate a fatal compile-time error, you can use the pre-processor #error directive. 20 * 21 * @code 22 * #error "That shouldn't have happened!" 23 * @endcode 24 * 25 * If the compiler evaluates this line, it will report the error and stop the compile. 26 * 27 * For example, you could use this to check some user-defined compile-time variables: 28 * 29 * @code 30 * #define NUM_PORTS 7 31 * #if (NUM_PORTS > 4) 32 * #error "NUM_PORTS must be less than 4" 33 * #endif 34 * @endcode 35 * 36 * Reporting Run-Time Errors: 37 * To generate a fatal run-time error, you can use the mbed error() function. 38 * 39 * @code 40 * error("That shouldn't have happened!"); 41 * @endcode 42 * 43 * If the mbed running the program executes this function, it will print the 44 * message via the USB serial port, and then die with the blue lights of death! 45 * 46 * The message can use printf-style formatting, so you can report variables in the 47 * message too. For example, you could use this to check a run-time condition: 48 * 49 * @code 50 * if(x >= 5) { 51 * error("expected x to be less than 5, but got %d", x); 52 * } 53 * #endcode 54 */ 55 56 #ifdef __cplusplus 57 extern "C" { 58 #endif 59 60 void error(const char* format, ...); 61 62 #ifdef __cplusplus 63 } 64 #endif 65 66 #endif 67