Tag: 例外

如何使用goto模拟C中的exception?

我在C中编写并发事务库,发现了以下问题。 让我们考虑一个示例事务成员伪代码,其中“transaction”表示与事务主机的通信通道: transaction = trans_join(); do_some_ops(); /* receive the data from the master */ trans_rcv(transaction, data); do_some_ops(); trans_send(transaction, answer); /* wait for the possibility for voting */ trans_ready(transaction); /* vote for commiting and wait for the voting results. */ if(trans_commit(answer)) { printf(“Final commiting the changes.\n”); } else { printf(“Rolling back the changes.\n”); } 在并发交易中,我们只有在要求主人投票时才能投票。 但是,主服务器可以随时调用trans_abort(member) […]

gcc – 属性nothrow用于什么?

我正在浏览一些gcc属性列表,我发现这个引起我注意的那个: nothrow The nothrow attribute is used to inform the compiler that a function cannot throw an exception. For example, most functions in the standard C library can be guaranteed not to throw an exception with the notable exceptions of qsort and bsearch that take function pointer arguments. The nothrow attribute is not implemented in […]

捕获操作码0xCC作为例外

假设C程序可能触发操作码0xCC的exception 我该怎么抓住它? 我试过了: __try { …some code } __except(GetExceptionCode()==EXCEPTION_EXECUTE_HANDLER) { _tprintf(_T(“Error\n”),i); return 0; } 这不适合我。 我究竟做错了什么? 谢谢!