forked

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_error.h Source File

mbed_error.h

00001 
00002 /** \addtogroup platform */
00003 /** @{*/
00004 /* mbed Microcontroller Library
00005  * Copyright (c) 2006-2013 ARM Limited
00006  *
00007  * Licensed under the Apache License, Version 2.0 (the "License");
00008  * you may not use this file except in compliance with the License.
00009  * You may obtain a copy of the License at
00010  *
00011  *     http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  * Unless required by applicable law or agreed to in writing, software
00014  * distributed under the License is distributed on an "AS IS" BASIS,
00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  * See the License for the specific language governing permissions and
00017  * limitations under the License.
00018  */
00019 #ifndef MBED_ERROR_H
00020 #define MBED_ERROR_H
00021 
00022 
00023 
00024 /** To generate a fatal compile-time error, you can use the pre-processor #error directive.
00025  *
00026  * @param format    C string that contains data stream to be printed.
00027  *                  Code snippets below show valid format.
00028  *
00029  * @code
00030  * #error "That shouldn't have happened!"
00031  * @endcode
00032  *
00033  * If the compiler evaluates this line, it will report the error and stop the compile.
00034  *
00035  * For example, you could use this to check some user-defined compile-time variables:
00036  *
00037  * @code
00038  * #define NUM_PORTS 7
00039  * #if (NUM_PORTS > 4)
00040  *     #error "NUM_PORTS must be less than 4"
00041  * #endif
00042  * @endcode
00043  *
00044  * Reporting Run-Time Errors:
00045  * To generate a fatal run-time error, you can use the mbed error() function.
00046  *
00047  * @code
00048  * error("That shouldn't have happened!");
00049  * @endcode
00050  *
00051  * If the mbed running the program executes this function, it will print the
00052  * message via the USB serial port, and then die with the blue lights of death!
00053  *
00054  * The message can use printf-style formatting, so you can report variables in the
00055  * message too. For example, you could use this to check a run-time condition:
00056  *
00057  * @code
00058  * if(x >= 5) {
00059  *     error("expected x to be less than 5, but got %d", x);
00060  * }
00061  * @endcode
00062  *
00063  *
00064  */
00065 
00066 #ifdef __cplusplus
00067 extern "C" {
00068 #endif
00069 void error(const char* format, ...);
00070 
00071 #ifdef __cplusplus
00072 }
00073 #endif
00074 
00075 #endif
00076 
00077 /** @}*/