-1

我偶尔会收到 OAuthException 并试图通过以下方式捕获它:

rescue OAuthException => exception
# exception handling code here

但是我得到:

rescue in <main>': uninitialized constant OAuthException (NameError)

知道我错过了什么吗?

==== 更新

这是我目前解决的方法。我必须做一个 message.match() 的事实似乎有点 hacky。

rescue GemModule::GemSubmodule::APIError => exception
    if exception.message.match("OAuthException") 

有什么改进吗?

4

1 回答 1

0
begin
  raise OAuthException, 'hello'
rescue OAuthException => e
  puts e
end

--output:--
1.rb:3:in `rescue in <main>': uninitialized constant OAuthException (NameError)
    from 1.rb:1:in `<main>'

.

class OAuthException < Exception
end

begin
  raise OAuthException, 'hello'
rescue OAuthException => e
  puts e
end

--output:--
hello

错误消息告诉您在 ruby​​ 中没有 OAuthException 之类的东西。

于 2013-07-01T00:50:32.917 回答