DEV Community

Discussion on: Why do all the dynamic languages catch name errors by default?

mattschwartz profile image
Matthew Schwartz

The simple explanation would be that all runtime errors should throw an exception. The open-ended catch would then need to catch them. Better to throw an exception and let the developer choose how to proceed. I personally think it's better to get an exception than let the code continue when there's been a coding mistake. Much easier to track down bugs.

yujiri8 profile image
Ryan Westlund Author

I understand them wanting to have name errors be catchable, but they don't have to be part of the standard exception class. Why couldn't NameError just not be a subtype of StandardError or Exception? You could still catch it if you wanted with except BaseException or except (Exception, NameError).