ruby / TryRuby

This 4th iteration of TryRuby is a website where you can learn the Ruby language.
https://try.ruby-lang.org
MIT License
226 stars 97 forks source link

Rescue `Exception` class to display all errors #111

Closed pocke closed 2 years ago

pocke commented 2 years ago

Problem

Currently eval_code rescues StandardError, so it does not display Exception.

I realized this problem when I causes a NotImplementedError, which doesn't inherit StandardError. Opal has not-implemented methods by design. For example, destructive methods for String. Some of these methods, such as String#gsub!, are popular, so the user may try to execute them.

However, currently NotImplementedError is not rescued, so it displays nothing if NotImplementedError occurs. I think it is confusing behavior.

Solution

Rescue Exception to display all errors.

Screenshots

before

211226201425

after

211226201434

hmdne commented 2 years ago

Nice catch! I haven't noticed that NotImplementedError is not a StandardError!