Pablo Rodríguez
Pablo Rodríguez

Reputation: 78

Does C language have Try and Catch?

As I understand C language doesn't have this feature but in gdb is used: https://fossies.org/linux/gdb/gdb/gdbserver/linux-low.c Line 1534

TRY
     /* Flush any pending changes to the process's registers.  */
   {
     regcache_invalidate_thread (thread);
     /* Finally, let it resume.  */
     if (the_low_target.prepare_to_resume != NULL)
   the_low_target.prepare_to_resume (lwp);
   }
 CATCH (ex, RETURN_MASK_ERROR)
   {
     if (!check_ptrace_stopped_lwp_gone (lwp))
   throw_exception (ex);
   }
 END_CATCH

Please explain how is this possible?

Thanks

Upvotes: 1

Views: 84

Answers (2)

Benjam
Benjam

Reputation: 1750

after a quick look into the link, I can observe std::vector, std::move,...

It seems the code contains c++.

Here is one definition of the TRY macro: http://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/common/common-exceptions.h;hb=e3624a40aeb31065c968d0d3a1d55fdf8e8a4e3c#l246

Upvotes: 1

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385088

No, C does not have exceptions.

Somewhere inside the gdbserver code, are defined TRY, CATCH and END_CATCH as macros that simulate exceptions.

Upvotes: 3

Related Questions