How are exceptions implemented under the hood?

前端 未结 10 1462
粉色の甜心
粉色の甜心 2020-12-07 07:43

Just about everyone uses them, but many, including me simply take it for granted that they just work.

I am looking for high-quality material. Languages I use are: Ja

10条回答
  •  悲&欢浪女
    2020-12-07 08:22

    Some runtimes like the Objective-C runtime have zero-cost 64-bit exceptions. What that means is that it doesn't cost anything to enter a try block. However, this is quite costly when the exception is thrown. This follows the paradigm of "optimize for the average case" - exceptions are meant to be exceptional, so it is better to make the case when there are no exceptions really fast, even if it comes at the cost of significantly slower exceptions.

提交回复
热议问题