I want to send e-mail when an exception will occur. What is important
mail should contain backtrace.
At first I redefined initialize method in
Exception class, it worked but of course I didnt have access to backtrace. Now I have redefined set_backtrace method. It works as I want to, its access to backtrace and message of exception. I send
mail directly from set_backtrace, because I noticed that method is
called every
time an exception occurs.
Is it correct way? Maybe, you could propose better solution of my
problem?
Unless I completely misunderstood you, why not just do:
begin
Do whatever it is you’re going to do
rescue Exception => e
Create your email
message_string = “An error has occurred. Backtrace: #{e.backtrace}”
Email it off however.
end
Of course its the simplest way, but Ill have to invoke that in every
rescue block. So, let`s say that there is uncatched exception, even
then mail should be sent. I redefined set_backtrace in Exception class.
I get the strange feeling though that you want more than this…?
I hope that now my problem is clear.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.