I messed up the merge, so pushing it over to another repo so I don't lose it. Will tidy up and remove later
Dependencies: BufferedSerial FatFileSystemCpp mbed
error.h@22:0dd9c1b5664a, 2021-07-05 (annotated)
- Committer:
- AndyA
- Date:
- Mon Jul 05 15:30:14 2021 +0000
- Revision:
- 22:0dd9c1b5664a
First pass at adding UDP FreeD output
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AndyA | 22:0dd9c1b5664a | 1 | /* mbed Microcontroller Library - error |
AndyA | 22:0dd9c1b5664a | 2 | * Copyright (c) 2006-2009 ARM Limited. All rights reserved. |
AndyA | 22:0dd9c1b5664a | 3 | * sford |
AndyA | 22:0dd9c1b5664a | 4 | */ |
AndyA | 22:0dd9c1b5664a | 5 | |
AndyA | 22:0dd9c1b5664a | 6 | #ifndef MBED_ERROR_H |
AndyA | 22:0dd9c1b5664a | 7 | #define MBED_ERROR_H |
AndyA | 22:0dd9c1b5664a | 8 | |
AndyA | 22:0dd9c1b5664a | 9 | /* Reporting Compile-Time Errors: |
AndyA | 22:0dd9c1b5664a | 10 | * To generate a fatal compile-time error, you can use the pre-processor #error directive. |
AndyA | 22:0dd9c1b5664a | 11 | * |
AndyA | 22:0dd9c1b5664a | 12 | * > #error "That shouldn't have happened!" |
AndyA | 22:0dd9c1b5664a | 13 | * |
AndyA | 22:0dd9c1b5664a | 14 | * If the compiler evaluates this line, it will report the error and stop the compile. |
AndyA | 22:0dd9c1b5664a | 15 | * |
AndyA | 22:0dd9c1b5664a | 16 | * For example, you could use this to check some user-defined compile-time variables: |
AndyA | 22:0dd9c1b5664a | 17 | * |
AndyA | 22:0dd9c1b5664a | 18 | * > #define NUM_PORTS 7 |
AndyA | 22:0dd9c1b5664a | 19 | * > #if (NUM_PORTS > 4) |
AndyA | 22:0dd9c1b5664a | 20 | * > #error "NUM_PORTS must be less than 4" |
AndyA | 22:0dd9c1b5664a | 21 | * > #endif |
AndyA | 22:0dd9c1b5664a | 22 | * |
AndyA | 22:0dd9c1b5664a | 23 | * Reporting Run-Time Errors: |
AndyA | 22:0dd9c1b5664a | 24 | * To generate a fatal run-time error, you can use the mbed error() function. |
AndyA | 22:0dd9c1b5664a | 25 | * |
AndyA | 22:0dd9c1b5664a | 26 | * > error("That shouldn't have happened!"); |
AndyA | 22:0dd9c1b5664a | 27 | * |
AndyA | 22:0dd9c1b5664a | 28 | * If the mbed running the program executes this function, it will print the |
AndyA | 22:0dd9c1b5664a | 29 | * message via the USB serial port, and then die with the blue lights of death! |
AndyA | 22:0dd9c1b5664a | 30 | * |
AndyA | 22:0dd9c1b5664a | 31 | * The message can use printf-style formatting, so you can report variables in the |
AndyA | 22:0dd9c1b5664a | 32 | * message too. For example, you could use this to check a run-time condition: |
AndyA | 22:0dd9c1b5664a | 33 | * |
AndyA | 22:0dd9c1b5664a | 34 | * > if(x >= 5) { |
AndyA | 22:0dd9c1b5664a | 35 | * > error("expected x to be less than 5, but got %d", x); |
AndyA | 22:0dd9c1b5664a | 36 | * > } |
AndyA | 22:0dd9c1b5664a | 37 | */ |
AndyA | 22:0dd9c1b5664a | 38 | |
AndyA | 22:0dd9c1b5664a | 39 | #if 0 // for documentation only |
AndyA | 22:0dd9c1b5664a | 40 | /* Function: error |
AndyA | 22:0dd9c1b5664a | 41 | * Report a fatal runtime error |
AndyA | 22:0dd9c1b5664a | 42 | * |
AndyA | 22:0dd9c1b5664a | 43 | * Outputs the specified error message to stderr so it will appear via the USB |
AndyA | 22:0dd9c1b5664a | 44 | * serial port, and then calls exit(1) to die with the blue lights of death. |
AndyA | 22:0dd9c1b5664a | 45 | * |
AndyA | 22:0dd9c1b5664a | 46 | * Variables: |
AndyA | 22:0dd9c1b5664a | 47 | * format - printf-style format string, followed by associated variables |
AndyA | 22:0dd9c1b5664a | 48 | */ |
AndyA | 22:0dd9c1b5664a | 49 | void error(const char* format, ...); |
AndyA | 22:0dd9c1b5664a | 50 | #endif |
AndyA | 22:0dd9c1b5664a | 51 | |
AndyA | 22:0dd9c1b5664a | 52 | #include <stdlib.h> |
AndyA | 22:0dd9c1b5664a | 53 | |
AndyA | 22:0dd9c1b5664a | 54 | #ifdef NDEBUG |
AndyA | 22:0dd9c1b5664a | 55 | #define error(...) (exit(1)) |
AndyA | 22:0dd9c1b5664a | 56 | #else |
AndyA | 22:0dd9c1b5664a | 57 | #include <stdio.h> |
AndyA | 22:0dd9c1b5664a | 58 | #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1)) |
AndyA | 22:0dd9c1b5664a | 59 | #endif |
AndyA | 22:0dd9c1b5664a | 60 | |
AndyA | 22:0dd9c1b5664a | 61 | #endif |