On 10/24/22 18:51, Pedro Alves wrote: > > > On 2022-10-24 5:43 p.m., Tom de Vries wrote: >> On 10/24/22 18:36, Pedro Alves wrote: >>> On 2022-10-24 9:49 a.m., Tom de Vries via Gdb-patches wrote: >>> >>>> +#define RETHROW_ON_TARGET_CLOSE_ERROR(E)                \ >>>> +  do                                    \ >>>> +    {                                    \ >>>> +      if ((E).reason != 0)                        \ >>>> +    {                                \ >>>> +      /* Can't set the breakpoint.  */                \ >>>> +                                    \ >>>> +      if ((E).error == TARGET_CLOSE_ERROR)                \ >>>> +        /* If the target has closed then it will have deleted any    \ >>>> +           breakpoints inserted within the target inferior, as a    \ >>>> +           result any further attempts to interact with the        \ >>>> +           breakpoint objects is not possible.  Just rethrow the    \ >>>> +           error.  Don't use E to rethrow, to prevent object    \ >>>> +           slicing of the exception.  */                \ >>>> +        throw;                            \ >>>> +    }                                \ >>>> +    } while (0) >>> >>> Is there a reason this is a macro instead of a function? >> >> yes, the throw without expression. >> >> Do you know of a way to do this using a function? > > WDYM? I believe it should Just Work. E.g.: > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > #include > > struct excpt > { > }; > > struct excpt2 : excpt > { > }; > > void > rethrow () > { > throw; > } > > int main () > { > try > { > try > { > throw excpt2{}; > } > catch (const excpt &) > { > rethrow (); > } > } > catch (const excpt2 &) > { > printf ("caught excpt2\n"); > } > return 0; > } > > $ g++ test_rethrow.cc -o test_rethrow > $ ./test_rethrow > caught excpt2 > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hmm, it does indeed, I didn't realize this was possible. Fixed in attached patch. Any further comments? Thanks, - Tom