On

67 1

Now there's a test code:
Def study_ruby_exception arg_1
begin
Puts 10/arg_1
Rescue exception => e
Puts e. Message.
end
end
Study_ruby_exception 0
When I run it, it prints: A divided by 0 divisor is zero exception
I want all the stack messages for this exception. For example, how do you call a relationship when you get this code? Which file is in the wrong way?!
I should be able to output.

1 Answers

62 0

The exception class a backtrace method retur & an array containing the 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

By the way, there are two words. Rescue doesn't necessarily have to be with begin.

Your example can be written in this way.

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