@@ -133,6 +133,26 @@ static void setup_handler() {
133133}
134134#endif
135135
136+ bool maybe_print_custom_stack (vdynamic * ret ) {
137+ hl_type * exct = ret -> t ;
138+ while (exct -> kind == HOBJ ) {
139+ if (exct -> obj -> super == NULL ) {
140+ if (ucmp (exct -> obj -> name , USTR ("haxe.Exception" )) == 0 ) {
141+ hl_field_lookup * f = hl_lookup_find (exct -> obj -> rt -> lookup , exct -> obj -> rt -> nlookup , hl_hash_gen (USTR ("_hx_customStack" ), true));
142+ if (f == NULL || f -> field_index < 0 ) break ;
143+ vdynamic * customStack = * (vdynamic * * )((char * )(ret ) + f -> field_index );
144+ if (customStack != NULL ) {
145+ uprintf (hl_to_string (customStack ));
146+ return true;
147+ }
148+ }
149+ break ;
150+ }
151+ exct = exct -> obj -> super ;
152+ }
153+ return false;
154+ }
155+
136156#ifdef HL_WIN
137157int wmain (int argc , pchar * argv []) {
138158#else
@@ -240,11 +260,13 @@ int main(int argc, pchar *argv[]) {
240260 ctx .ret = hl_dyn_call_safe (& cl ,NULL ,0 ,& isExc );
241261 hl_profile_end ();
242262 if ( isExc ) {
243- varray * a = hl_exception_stack ();
244- int i ;
245263 uprintf (USTR ("Uncaught exception: %s\n" ), hl_to_string (ctx .ret ));
246- for (i = 0 ;i < a -> size ;i ++ )
247- uprintf (USTR ("Called from %s\n" ), hl_aptr (a ,uchar * )[i ]);
264+ if (!maybe_print_custom_stack (ctx .ret )) {
265+ varray * a = hl_exception_stack ();
266+ int i ;
267+ for (i = 0 ; i < a -> size ; i ++ )
268+ uprintf (USTR ("Called from %s\n" ), hl_aptr (a , uchar * )[i ]);
269+ }
248270 hl_debug_break ();
249271 hl_global_free ();
250272 return 1 ;
0 commit comments