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