-1

私は時折 OAuthException を取得しており、それをキャッチしようとしています:

rescue OAuthException => exception
# exception handling code here

しかし、私は得る:

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

私が見逃しているものはありますか?

====更新

これが私が現在それを解決した方法です。私が message.match() をしなければならないという事実は、少しハックなようです。

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 に答える