Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果你用 C 语言编写一个 ruby 方法作为函数使用rb_raise,调用后的函数部分不会被执行,程序将停止,你会认为rb_raise使用了exit()。但是,如果您在 ruby 中挽救异常,例如:
rb_raise
exit()
begin method_that_raises_an_exception rescue end puts 'You wil still get here.'
ruby 代码将继续运行,但您的函数将停止执行。如何rb_raise做到这一点?
大概它使用setjmp(在调用方法之前)和longjmp(在rb_raise)。
setjmp
longjmp