ruby-on-rails - ruby 怎么打印输出 异常信息的详细消息?
PHP中文网
PHP中文网 2017-04-21 10:56:14
0
1
1088

现在有一个测试代码:
def study_ruby_exception arg_1
begin
puts 10/arg_1
rescue Exception => e
puts e.message
end
end
study_ruby_exception 0
当我运行的时候会打印输出:pided by 0 除数为零异常
我想得到这个异常的所有堆栈消息。例如:接防执行这个代码的时候是怎么的调用关系。错在哪个文件的哪 个方法里面等!
我应该怎么输出呢?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
大家讲道理

Exception class has a backtrace method that returns an array containing a stack...

Reference code...

def study_ruby_exception arg_1
    begin
        puts 10/arg_1
    rescue Exception => e
        puts e.backtrace
    end
end

study_ruby_exception 0

A few words by the way...rescue actually does not have to appear together with begin...

Your example can actually be written like this...

def study_ruby_exception arg_1
    puts 10/arg_1
rescue Exception => e
    puts e.backtrace
end

study_ruby_exception 0
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!