rescueのデフォルト引数は
StandardError rescueで捕捉できるのは、引数に指定した例外クラス or 引数に指定した例外クラスを継承したクラス rescueでは StandardError を捕捉するべき
Ext JS Modern - API documentation from Sencha. When specified this property causes the Ext.data.Model#idProperty of newly created records to be sent to the server as this name instead of the value of the idProperty. Installation on openSUSE and SLES platforms warns about unknown key signature. Omnibus GitLab packages are signed with GPG keys in addition to the package repositories providing signed metadata. This ensures authenticity and integrity of the packages that are distributed to the users. But I observed that this problem appears when we associate subscriptions to content-host. Either updating the subscriptions under selected activation-key with which systems were regsietered. Or add the subscriptions from UI to registered content-host, if systems are registered without activation-key.
上記2つの違いは
rescue の引数に ActiveRecord::RecordNotFound の有無です。指定しない場合は undefined method `do_something' for main:Object が捕捉されます。 指定した場合は捕捉されず、begin end後に例外が発生します。 なぜなら、 ActiveRecord::RecordNotFound を引数に指定した場合、 ActiveRecord::RecordNotFound か、 ActiveRecord::RecordNotFound を継承したエラーのみ、 rescue で捕捉することができるためです。NoMethodError は、 ActiveRecord::RecordNotFound を継承していない、かつ、 ActiveRecord::RecordNotFound ではないので捕捉することができません。
![]()
補足すると、NoMethodErrorは
StandardError > NameError > NoMethodError ActiveRecord::RecordNotFoundは StandardError > ActiveRecord::ActiveRecordError となっています。
話がそれましたが、たとえば
NoMethodError の親である、 StandardError を rescue に指定すれば捕捉することができます
さらに、
StandardError の親である、 Exception を指定しても同じです。
Exception の親となる例外のクラスは存在しません。だとすると、エラーの親である、 Exception を捕捉すればいいのではないかと考えますが、それは良くないです。なぜなら、 Exception はシステムレベルの例外も含まれます。アプリケーションレベルの例外を捉えたいのではないでしょうか。例として、ctrl + c で実行中のプログラムを終了する場合、そこで処理は終了するべきですが、このように書くと終了しません。
このような動作は想定していないと思います。
また、このような例もあります。
Exception を継承した、例外クラスを捕捉します。
間違えました。これでは
Exception を捕捉できません。
rescue に引数を指定しない場合、デフォルトで StandardError が引数になるからです。
今回の場合、引数を指定しないので、
StandardError が引数です。Exception > StandardError となっているため、 Exception を捕捉することができませんでした。なので
このようにすることで、
Exception を捕捉することができます。
参考にさせていただきました
https://qiita.com/ngron/items/4c319ae7340b72c7e566
http://ruby-doc.com/docs/ProgrammingRuby/ https://blog.toshimaru.net/ruby-standard-error/ https://qiita.com/tsubasakat/items/6825bcefcad26da3471b https://www.honeybadger.io/blog/ruby-exception-vs-standarderror-whats-the-difference/
下記の通りすると、例外クラスを見ることができます。(2パターン)
1 @scivola さんに教えてくいただきました
2 http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy/
I am using Rails 3.1.10 with Ruby 1.9.3.
What the hell I am doing, It just made me totally sick. I am using MongoDB with gem mongoid 2.2. I have really tried alot it is always giving me this error I have the latest elastic search gem version and when I run 'Article.elasticsearch.client.cluster.health'
LoadError: cannot load such file -- {'cluster_name':'AliAhmed','status':'yellow','timed_out':false,'number_of_nodes':1,'number_of_data_nodes':1,'active_primary_shards':5,'active_shards':5,'relocating_shards':0,'initializing_shards':0,'unassigned_shards':5} '1.9.3-p551 :016 >
from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:234:in load' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:234:in block in load'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:223:in block in load_dependency' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:640:in new_constants_in'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:223:in load_dependency' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:234:in load'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-transport-1.0.12/lib/elasticsearch/transport/transport/serializer/multi_json.rb:24:in load' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-transport-1.0.12/lib/elasticsearch/transport/transport/base.rb:230:in perform_request'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-transport-1.0.12/lib/elasticsearch/transport/transport/http/faraday.rb:20:in perform_request' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-transport-1.0.12/lib/elasticsearch/transport/client.rb:119:in perform_request'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-api-1.0.12/lib/elasticsearch/api/namespace/common.rb:21:in perform_request' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-api-1.0.12/lib/elasticsearch/api/actions/cluster/health.rb:49:in health'from (irb):15 from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.1.10/lib/rails/commands/console.rb:45:in start' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.1.10/lib/rails/commands/console.rb:8:in start'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.1.10/lib/rails/commands.rb:40:in <top (required)>' from script/rails:6:in require'from script/rails:6:in ` ![]()
Also
Nomethoderror Undefined Method Key For Json Ext Generator State Of Florida
Article.import '
NoMethodError: undefined method dump' for MultiJson:Module from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-api-1.0.12/lib/elasticsearch/api/utils.rb:87:in block in __bulkify'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-api-1.0.12/lib/elasticsearch/api/utils.rb:77:in map' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-api-1.0.12/lib/elasticsearch/api/utils.rb:77:in __bulkify'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/elasticsearch-api-1.0.12/lib/elasticsearch/api/actions/bulk.rb:75:in bulk' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/bundler/gems/elasticsearch-rails-ded203569208/elasticsearch-model/lib/elasticsearch/model/importing.rb:123:in block in import'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/bundler/gems/elasticsearch-rails-ded203569208/elasticsearch-model/lib/elasticsearch/model/adapters/mongoid.rb:69:in block in __find_in_batches' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/bundler/gems/elasticsearch-rails-ded203569208/elasticsearch-model/lib/elasticsearch/model/adapters/mongoid.rb:68:in each_slice'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/bundler/gems/elasticsearch-rails-ded203569208/elasticsearch-model/lib/elasticsearch/model/adapters/mongoid.rb:68:in __find_in_batches' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/bundler/gems/elasticsearch-rails-ded203569208/elasticsearch-model/lib/elasticsearch/model/importing.rb:122:in import'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/bundler/gems/elasticsearch-rails-ded203569208/elasticsearch-model/lib/elasticsearch/model.rb:115:in import' from (irb):14 from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.1.10/lib/rails/commands/console.rb:45:in start'from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.1.10/lib/rails/commands/console.rb:8:in start' from /home/aliahmed/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.1.10/lib/rails/commands.rb:40:in <top (required)>'from script/rails:6:in require' from script/rails:6:in
Nomethoderror Undefined Method Key For Json Ext Generator State Of Georgia
Please help me with this.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |