问题描述:

Is there anyway I can override default exception thrower method in ruby ?

Something like, I want to puts "Hello world" in every time error occurs in my application.

By default

2.2.2 :001 > sure_error

NameError: undefined local variable or method `sure_error' for main:Object

from (irb):1

from /home/gas/.rvm/rubies/ruby-2.2.2/bin/irb:11:in `<main>'

2.2.2 :002 >

What I want

2.2.2 :001 > sure_error

Hello World

NameError: undefined local variable or method `sure_error' for main:Object

from (irb):1

from /home/gas/.rvm/rubies/ruby-2.2.2/bin/irb:11:in `<main>'

2.2.2 :002 >

I don't want to override raise method and put 'begin, rescue, raise' to all methods in my whole application, because it is so big right now.

相关阅读:
Top