简体   繁体   中英

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

No, C does not have exceptions.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM