context = V8::Context.new(timeout: 20000) do |context|
context['ForbidAccess'] = ->(message) { throw NotImplementedError }
end
begin
context.eval("ForbidAccess();")
rescue => e
puts "e.class = #{e.class.name}"
puts "e.causes = #{e.causes}"
puts "e.root_cause = #{e.root_cause}"
puts "e.root_cause.class = #{e.root_cause.class}"
end
控制檯輸出:獲取Ruby異常
e.class = V8::Error
e.causes = [#<V8::Error: uncaught throw NotImplementedError>, #<ArgumentError: uncaught throw NotImplementedError>]
e.root_cause = uncaught throw NotImplementedError
e.root_cause.class = ArgumentError
我如何獲得訪問NotImplementedError對象?
如果正在閱讀您的問題,您想知道如何訪問您的Ruby代碼中調用它的JavaScript異常? – Doon 2014-10-05 23:51:28
我用'扔'而不是'提高'。就這樣。 – Jacob 2014-10-06 21:26:14