@@ -940,6 +940,16 @@ MBED_NORETURN void error(const char *format, ...) MBED_PRINTF(1, 2);
940940 */
941941#define MBED_MAKE_ERROR (module , error_code ) MBED_MAKE_SYSTEM_ERROR(module, error_code)
942942
943+ /**
944+ * Callback/Error hook function prototype. Applications needing a callback when an error is reported can use mbed_set_error_hook function
945+ * to register a callback/error hook function using the following prototype. When an error happens in the system error handling
946+ * implementation will invoke this callback with the mbed_error_status_t reported and the error context at the time of error.
947+ * @param error_ctx Error context structure associated with this error.
948+ * @return void
949+ *
950+ */
951+ typedef void (* mbed_error_hook_t )(const mbed_error_ctx * error_ctx );
952+
943953/**
944954 * Callback/Error hook function. If application implementation needs to receive this callback when an error is reported,
945955 * mbed_error_hook function should be overridden with custom implementation. When an error happens in the system error handling
@@ -950,7 +960,6 @@ MBED_NORETURN void error(const char *format, ...) MBED_PRINTF(1, 2);
950960 */
951961void mbed_error_hook (const mbed_error_ctx * error_context );
952962
953-
954963/**
955964 * Callback function for reporting error context during boot up. When MbedOS error handling system detects a fatal error
956965 * it will auto-reboot the system(if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED is enabled) after capturing the
@@ -1070,6 +1079,30 @@ bool mbed_get_error_in_progress(void);
10701079 */
10711080MBED_NORETURN mbed_error_status_t mbed_error (mbed_error_status_t error_status , const char * error_msg , unsigned int error_value , const char * filename , int line_number );
10721081
1082+ /**
1083+ * Registers an application defined error callback with the error handling system.
1084+ * This function will be called with error context info whenever system handles a mbed_error/mbed_warning call
1085+ * NOTE: This function should be implemented for re-entrancy as multiple threads may invoke mbed_error which may cause error hook to be called.
1086+ * @param custom_error_hook mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
1087+ * @return 0 or MBED_SUCCESS on success.
1088+ * MBED_ERROR_INVALID_ARGUMENT in case of NULL for custom_error_hook
1089+ *
1090+ * @code
1091+ *
1092+ * mbed_error_status_t my_custom_error_hook(mbed_error_status_t error_status, const mbed_error_ctx *error_ctx) {
1093+ * //Do something with the error_status or error_ctx
1094+ * }
1095+ *
1096+ * mbed_set_error_hook( my_custom_error_hook )
1097+ *
1098+ * @endcode
1099+ * @note The erro hook function implementation should be re-entrant.
1100+ *
1101+ * @deprecated You should use an overridden mbed_error_hook() function if you like to catch errors in your application.
1102+ * With mbed_set_error_hook() it is not possible to catch errors before your application started.
1103+ */
1104+ mbed_error_status_t mbed_set_error_hook (mbed_error_hook_t custom_error_hook );
1105+
10731106/**
10741107 * Reads the first error context information captured.
10751108 * @param error_info This is the mbed_error_context info captured as part of the first mbed_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
0 commit comments