Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby
def recurse; recurse; end
begin
puts(*(0...140000))
rescue Exception => e
puts "caught exception: #{e.inspect}"
end
begin
eval "raise RuntimeError, 'kapow'"
rescue Exception => e
puts "caught exception: #{e.inspect}"
end
begin
eval "recurse"
rescue Exception => e
puts "caught exception: #{e.inspect}"
end
begin
eval "puts(*(0...140000))"
rescue Exception => e
puts "caught exception: #{e.inspect}"
end
begin
eval "<COMPLETELY INVALID SYNTAX>"
rescue Exception => e
puts "caught exception: #{e.inspect}"
end
begin
arg_string = (0...140000).to_a.join(", ")
eval "puts(#{arg_string})"
rescue Exception => e
puts "caught exception: #{e.inspect}"
end
puts "Never reached."
gabriel@last:~/Code/ruby$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
gabriel@last:~/Code/ruby$ ruby exceptions_in_eval.rb
caught exception: #<SystemStackError: stack level too deep>
caught exception: #<RuntimeError: kapow>
caught exception: #<SystemStackError: stack level too deep>
caught exception: #<SystemStackError: stack level too deep>
caught exception: #<SyntaxError: (eval):1: syntax error, unexpected '<'
<COMPLETELY INVALID SYNTAX>
^
(eval):1: syntax error, unexpected $end
<COMPLETELY INVALID SYNTAX>
^>
(eval):0: stack level too deep (SystemStackError)
gabriel@last:~/Code/ruby$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment