开发者

How does ruby's rb_raise stop the execution of the c function calling it?

开发者 https://www.devze.com 2022-12-24 18:35 出处:网络
I开发者_运维百科f you write a ruby method as a function in C that uses rb_raise, the part of the function after the call will not get excecuted and the program will stop and you will think that rb_rai

I开发者_运维百科f you write a ruby method as a function in C that uses rb_raise, the part of the function after the call will not get excecuted and the program will stop and you will think that rb_raise used exit(). But if you rescue the exception in ruby, like:

begin
  method_that_raises_an_exception
rescue
end
puts 'You wil still get here.'

The ruby code will go on, but your function will stop excecuting. How does rb_raise make this happen?


Presumably it uses setjmp (before the method is called) and longjmp (in rb_raise).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号