Send personally caught exceptions?

Mohammad El-Abid's Avatar

Mohammad El-Abid

29 Apr, 2011 11:24 PM

How do I send off errors that I personally caught? I was told the following would work in the latest rails (3.0.7 I believe) I'm using the hoptoad_notifier gem

class HomeController < ApplicationController
def index

begin
  raise 'test begin-rescue-end'
rescue
  hoptoad_notify $!
end

end end

  1. 2 Posted by Matt Jankowski on 01 May, 2011 03:02 PM

    Matt Jankowski's Avatar

    Yes, that's correct for controllers when hoptoad_notify method is available. You can read more in the notifier plugin README - https://github.com/thoughtbot/hoptoad_notifier/blob/master/README.md

  2. Matt Jankowski closed this discussion on 01 May, 2011 03:02 PM.

  3. Mohammad El-Abid re-opened this discussion on 01 May, 2011 03:04 PM

  4. 3 Posted by Mohammad El-Abid on 01 May, 2011 03:04 PM

    Mohammad El-Abid's Avatar

    I tried that but it gave an error of undefined method. I'll recreate it in a few hours and post back.

    Sent from my iPod Touch 4G

  5. 4 Posted by Mohammad on 01 May, 2011 03:28 PM

    Mohammad's Avatar

    NoMethodError (undefined method hoptoad_notify' for #<HomeController:0x5505678> ): app/controllers/home_controller.rb:6:inrescue in index' app/controllers/home_controller.rb:3:in `index'

    Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatc
    h/middleware/templates/rescues/trace.erb (1.0ms)
    Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatc
    h/middleware/templates/rescues/
    request_and_response.erb (72.0ms)
    Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatc
    h/middleware/templates/rescues/diagnostics.erb within rescues/layout (119.5ms)

  6. 5 Posted by Harold Gimenez on 02 May, 2011 12:57 AM

    Harold Gimenez's Avatar

    Hi Mohammad,

    The method is actually called notify_hoptoad. Can you give it a shot?

    And just as an aside, I think it's clearer to grab the exception object in the rescue call and send it over to Hoptoad, instead of using $!. So even though both should work, try this:

    begin
      raise 'test begin-rescue-end'
    rescue Exception => e
      notify_hoptoad e
    end
    

    Let us know how that goes.

  7. 6 Posted by Mohammad El-Abid on 03 May, 2011 09:07 PM

    Mohammad El-Abid's Avatar

    Thank you Harold, that's what was wrong! It's working fine now.

  8. 7 Posted by Harold Gimenez on 03 May, 2011 09:10 PM

    Harold Gimenez's Avatar

    Glad it's working for you, and thanks for using Hoptoad!

  9. Harold Gimenez closed this discussion on 03 May, 2011 09:10 PM.

Comments are currently closed for this discussion. You can start a new one.