File tree 2 files changed +23
-6
lines changed
2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -150,14 +150,31 @@ static void do_global_ctors(void) {
150
150
(*--p)();
151
151
}
152
152
153
- extern " C" { extern void __unhandled_exception (); }
153
+ extern " C" {
154
+ extern void __unhandled_exception (const char *str);
154
155
156
+ static void __unhandled_exception_cpp ()
157
+ {
158
+ static bool terminating;
159
+ if (terminating)
160
+ abort ();
161
+ terminating = true ;
162
+ /* Use a trick from vterminate.cc to get any std::exception what() */
163
+ try {
164
+ __throw_exception_again;
165
+ } catch (const std::exception & e) {
166
+ __unhandled_exception ( e.what () );
167
+ } catch (...) {
168
+ __unhandled_exception ( " " );
169
+ }
170
+ }
155
171
172
+ }
156
173
157
174
void init_done () {
158
175
system_set_os_print (1 );
159
176
gdb_init ();
160
- std::set_terminate (__unhandled_exception );
177
+ std::set_terminate (__unhandled_exception_cpp );
161
178
do_global_ctors ();
162
179
esp_schedule ();
163
180
}
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ static const char* s_panic_func = 0;
40
40
static const char * s_panic_what = 0 ;
41
41
42
42
static bool s_abort_called = false;
43
- static bool s_unhandled_exception = false ;
43
+ static const char * s_unhandled_exception = NULL ;
44
44
45
45
void abort () __attribute__((noreturn ));
46
46
static void uart_write_char_d (char c );
@@ -121,7 +121,7 @@ void __wrap_system_restart_local() {
121
121
ets_putc ('\n' );
122
122
}
123
123
else if (s_unhandled_exception ) {
124
- ets_printf_P ("\nUnhandled exception\n" );
124
+ ets_printf_P ("\nUnhandled exception: %s \n" , s_unhandled_exception );
125
125
}
126
126
else if (s_abort_called ) {
127
127
ets_printf_P ("\nAbort called\n" );
@@ -237,8 +237,8 @@ void abort() {
237
237
raise_exception ();
238
238
}
239
239
240
- void __unhandled_exception () {
241
- s_unhandled_exception = true ;
240
+ void __unhandled_exception (const char * str ) {
241
+ s_unhandled_exception = str ;
242
242
raise_exception ();
243
243
}
244
244
You can’t perform that action at this time.
0 commit comments