From: "Dmitry V. Sabanin" Date: 2003-06-20T20:10:40+09:00 Subject: Re: rescuing errors.. catch-all --Boundary-00=_5su8+Ri5t4zAe2+ Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Friday 20 June 2003 08:04, Daniel Bretoi wrote: > Hi, > > Im trying to print all error information to the browser so I don't have > to monitor the apache log every time I have a syntax error. > One day i wrote special addition to Exception class, so it outputs quite pretty exception information to the browser window, it's attached. When it's included u can just do this: begin #code here rescue Exception => e # not sure about this, i always had rescue => e here e.backtrace_html if e.methods.include? 'backtrace_html' end All backtracing code is made by 'in-place html' couse i wanted it to be totally independent from any template engines and so on. Maybe it will be usefull to you. -- sdmitry -=- Dmitry V. Sabanin MuraveyLabs. --Boundary-00=_5su8+Ri5t4zAe2+ Content-Type: text/html; charset="koi8-r"; name="errors.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="errors.rb" class Exception def backtrace_html line_color = 'white' lineHead_color = '#FDDFA0' error_color = 'red' special_color = 'blue' adminMail = 'dmitry@iren.info' odd_color = 'F2E8B3' even_color = 'F5E693' errsect = to_s.scan (/^([\w\s]*)[|]{3}/) if errsect.length > 0 errtext = *to_s.scan(/[|]{3}(.*)$/) errtext = errtext.join('') else errtext = to_s errsect = 'Unexpected' end print " #{errsect} error! " colorifier = 0 backtrace.each do |line| fileName, lineNum, methodName = line.split(/:/) if line.scan(/\d*:in/).length > 0 methodName = *methodName.scan(/`\w*'/) methodName.gsub!(/[`']/,'') if methodName end if colorifier.divmod(2)[1] == 0 row_color = odd_color else row_color = even_color end print " " colorifier += 1 end print "

Ruby Error Report (Version #{VERSION}, platform #{RUBY_PLATFORM})

#{errsect} error:
There was an error while perfoming your request: #{CGI.escapeHTML(errtext)}
Exception type #{type.to_s}
File NameLine NumberMethod Name
#{fileName}#{lineNum}#{methodName if defined? methodName}
If you wish to help us, please e-mail our administrator about this error..
This report was generated at #{Time.now}.
" end end --Boundary-00=_5su8+Ri5t4zAe2+--