Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/platform/mbed_error.h@4:75df35ef4fb6, 2018-03-30 (annotated)
- Committer:
- borlanic
- Date:
- Fri Mar 30 14:07:05 2018 +0000
- Revision:
- 4:75df35ef4fb6
- Parent:
- 0:380207fcb5c1
commentar
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| borlanic | 0:380207fcb5c1 | 1 | |
| borlanic | 0:380207fcb5c1 | 2 | /** \addtogroup platform */ |
| borlanic | 0:380207fcb5c1 | 3 | /** @{*/ |
| borlanic | 0:380207fcb5c1 | 4 | /** |
| borlanic | 0:380207fcb5c1 | 5 | * \defgroup platform_error Error functions |
| borlanic | 0:380207fcb5c1 | 6 | * @{ |
| borlanic | 0:380207fcb5c1 | 7 | */ |
| borlanic | 0:380207fcb5c1 | 8 | /* mbed Microcontroller Library |
| borlanic | 0:380207fcb5c1 | 9 | * Copyright (c) 2006-2013 ARM Limited |
| borlanic | 0:380207fcb5c1 | 10 | * |
| borlanic | 0:380207fcb5c1 | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| borlanic | 0:380207fcb5c1 | 12 | * you may not use this file except in compliance with the License. |
| borlanic | 0:380207fcb5c1 | 13 | * You may obtain a copy of the License at |
| borlanic | 0:380207fcb5c1 | 14 | * |
| borlanic | 0:380207fcb5c1 | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
| borlanic | 0:380207fcb5c1 | 16 | * |
| borlanic | 0:380207fcb5c1 | 17 | * Unless required by applicable law or agreed to in writing, software |
| borlanic | 0:380207fcb5c1 | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
| borlanic | 0:380207fcb5c1 | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| borlanic | 0:380207fcb5c1 | 20 | * See the License for the specific language governing permissions and |
| borlanic | 0:380207fcb5c1 | 21 | * limitations under the License. |
| borlanic | 0:380207fcb5c1 | 22 | */ |
| borlanic | 0:380207fcb5c1 | 23 | #ifndef MBED_ERROR_H |
| borlanic | 0:380207fcb5c1 | 24 | #define MBED_ERROR_H |
| borlanic | 0:380207fcb5c1 | 25 | |
| borlanic | 0:380207fcb5c1 | 26 | |
| borlanic | 0:380207fcb5c1 | 27 | |
| borlanic | 0:380207fcb5c1 | 28 | /** To generate a fatal compile-time error, you can use the pre-processor #error directive. |
| borlanic | 0:380207fcb5c1 | 29 | * |
| borlanic | 0:380207fcb5c1 | 30 | * @param format C string that contains data stream to be printed. |
| borlanic | 0:380207fcb5c1 | 31 | * Code snippets below show valid format. |
| borlanic | 0:380207fcb5c1 | 32 | * |
| borlanic | 0:380207fcb5c1 | 33 | * @code |
| borlanic | 0:380207fcb5c1 | 34 | * #error "That shouldn't have happened!" |
| borlanic | 0:380207fcb5c1 | 35 | * @endcode |
| borlanic | 0:380207fcb5c1 | 36 | * |
| borlanic | 0:380207fcb5c1 | 37 | * If the compiler evaluates this line, it will report the error and stop the compile. |
| borlanic | 0:380207fcb5c1 | 38 | * |
| borlanic | 0:380207fcb5c1 | 39 | * For example, you could use this to check some user-defined compile-time variables: |
| borlanic | 0:380207fcb5c1 | 40 | * |
| borlanic | 0:380207fcb5c1 | 41 | * @code |
| borlanic | 0:380207fcb5c1 | 42 | * #define NUM_PORTS 7 |
| borlanic | 0:380207fcb5c1 | 43 | * #if (NUM_PORTS > 4) |
| borlanic | 0:380207fcb5c1 | 44 | * #error "NUM_PORTS must be less than 4" |
| borlanic | 0:380207fcb5c1 | 45 | * #endif |
| borlanic | 0:380207fcb5c1 | 46 | * @endcode |
| borlanic | 0:380207fcb5c1 | 47 | * |
| borlanic | 0:380207fcb5c1 | 48 | * Reporting Run-Time Errors: |
| borlanic | 0:380207fcb5c1 | 49 | * To generate a fatal run-time error, you can use the mbed error() function. |
| borlanic | 0:380207fcb5c1 | 50 | * |
| borlanic | 0:380207fcb5c1 | 51 | * @code |
| borlanic | 0:380207fcb5c1 | 52 | * error("That shouldn't have happened!"); |
| borlanic | 0:380207fcb5c1 | 53 | * @endcode |
| borlanic | 0:380207fcb5c1 | 54 | * |
| borlanic | 0:380207fcb5c1 | 55 | * If the mbed running the program executes this function, it will print the |
| borlanic | 0:380207fcb5c1 | 56 | * message via the USB serial port, and then die with the blue lights of death! |
| borlanic | 0:380207fcb5c1 | 57 | * |
| borlanic | 0:380207fcb5c1 | 58 | * The message can use printf-style formatting, so you can report variables in the |
| borlanic | 0:380207fcb5c1 | 59 | * message too. For example, you could use this to check a run-time condition: |
| borlanic | 0:380207fcb5c1 | 60 | * |
| borlanic | 0:380207fcb5c1 | 61 | * @code |
| borlanic | 0:380207fcb5c1 | 62 | * if(x >= 5) { |
| borlanic | 0:380207fcb5c1 | 63 | * error("expected x to be less than 5, but got %d", x); |
| borlanic | 0:380207fcb5c1 | 64 | * } |
| borlanic | 0:380207fcb5c1 | 65 | * @endcode |
| borlanic | 0:380207fcb5c1 | 66 | * |
| borlanic | 0:380207fcb5c1 | 67 | * |
| borlanic | 0:380207fcb5c1 | 68 | */ |
| borlanic | 0:380207fcb5c1 | 69 | |
| borlanic | 0:380207fcb5c1 | 70 | #ifdef __cplusplus |
| borlanic | 0:380207fcb5c1 | 71 | extern "C" { |
| borlanic | 0:380207fcb5c1 | 72 | #endif |
| borlanic | 0:380207fcb5c1 | 73 | void error(const char* format, ...); |
| borlanic | 0:380207fcb5c1 | 74 | |
| borlanic | 0:380207fcb5c1 | 75 | #ifdef __cplusplus |
| borlanic | 0:380207fcb5c1 | 76 | } |
| borlanic | 0:380207fcb5c1 | 77 | #endif |
| borlanic | 0:380207fcb5c1 | 78 | |
| borlanic | 0:380207fcb5c1 | 79 | #endif |
| borlanic | 0:380207fcb5c1 | 80 | |
| borlanic | 0:380207fcb5c1 | 81 | /** @}*/ |
| borlanic | 0:380207fcb5c1 | 82 | /** @}*/ |