C语言是否具有“尝试并抓住”功能?

时间:2019-03-02 23:15:46

标签: c try-catch

据我了解,C语言没有此功能,但在gdb中使用了: https://fossies.org/linux/gdb/gdb/gdbserver/linux-low.c第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

请说明这怎么可能?

谢谢

2 个答案:

答案 0 :(得分:3)

不,C没有例外。

Somewhere inside the gdbserver code被定义为SELECT pm.ProjectCode AS ProjectCode, bl.PartNum AS PartNum, SUM(pm.Quantity * bl.TotalQty) AS BOMItemCount, SUM( CASE WHEN blh.ParentPartNum = bl.PartNum THEN pm.Quantity * bl.TotalQty ELSE 0 END ) AS NextBOMItemCount, bl.mp AS mp, p.complete AS complete, bl.RMInd AS RMInd, bl.M_PartNum AS M_PartNum FROM projectmachine AS pm INNER JOIN projectbomlist AS bl ON pm.MachineListID = bl.MachineListID AND pm.ProjectCode = bl.ProjectCode INNER JOIN join projects AS p ON pm.ProjectCode = p.ProjectCode AND p.AfterProjectHeirarchyInd = 'Y' INNER JOIN projectbomlistheirarchy blh ON bl.ProjectCode = blh.ProjectCode WHERE pm.ProjectCode = 'AB212323' GROUP BY pm.ProjectCode, bl.PartNum, bl.mp, p.complete, bl.RMInd, bl.M_PartNum ORDER BY pm.ProjectCode, bl.PartNum TRYCATCH模拟异常的宏。

答案 1 :(得分:1)

快速浏览链接后,我可以观察到std :: vector,std :: move,...

似乎代码包含c ++。

这是TRY宏的一种定义: http://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/common/common-exceptions.h;hb=e3624a40aeb31065c968d0d3a1d55fdf8e8a4e3c#l246