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.
Fork of mbed-src by
error.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_ERROR_H 00017 #define MBED_ERROR_H 00018 00019 /** To generate a fatal compile-time error, you can use the pre-processor #error directive. 00020 * 00021 * @code 00022 * #error "That shouldn't have happened!" 00023 * @endcode 00024 * 00025 * If the compiler evaluates this line, it will report the error and stop the compile. 00026 * 00027 * For example, you could use this to check some user-defined compile-time variables: 00028 * 00029 * @code 00030 * #define NUM_PORTS 7 00031 * #if (NUM_PORTS > 4) 00032 * #error "NUM_PORTS must be less than 4" 00033 * #endif 00034 * @endcode 00035 * 00036 * Reporting Run-Time Errors: 00037 * To generate a fatal run-time error, you can use the mbed error() function. 00038 * 00039 * @code 00040 * error("That shouldn't have happened!"); 00041 * @endcode 00042 * 00043 * If the mbed running the program executes this function, it will print the 00044 * message via the USB serial port, and then die with the blue lights of death! 00045 * 00046 * The message can use printf-style formatting, so you can report variables in the 00047 * message too. For example, you could use this to check a run-time condition: 00048 * 00049 * @code 00050 * if(x >= 5) { 00051 * error("expected x to be less than 5, but got %d", x); 00052 * } 00053 * #endcode 00054 */ 00055 00056 #include <stdlib.h> 00057 #include "device.h" 00058 00059 #if DEVICE_STDIO_MESSAGES 00060 #include <stdio.h> 00061 #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1)) 00062 #else 00063 #define error(...) (exit(1)) 00064 #endif 00065 00066 #endif
Generated on Tue Jul 12 2022 21:21:33 by
