💾 Archived View for yujiri.xyz › software › catch-name-errors.gmi captured on 2023-06-14 at 14:21:31. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

➡️ Next capture (2023-09-08)

-=-=-=-=-=-=-

yujiri.xyz

Software

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

For all my experience with the try-catch paradigm in dynamic languages, I've *never* seen a situation where I wanted a *name error* in the try block to be caught. It's hard to imagine one. A name error is a typo 99% of the time, and a mistake 99% of the remainder. Catching it accidentally can lead to an especially frustrating debugging experience.

So why do *all* the dynamic languages have `catch` statements catch name errors by default?

Unlike Julia and Javascript, Python and Ruby have real exception hierarchy systems and allow multiple catch clauses that catch different kinds. But both of them still include name errors in a bare catch.

And their designers obviously realized that there are some exceptions you don't usually want to catch, as they have a class you can catch that excludes other things in that category (like `KeyboardInterrupt`s): `StandardError` in Ruby, `Exception` in Python (with `BaseException` being the real base class). But for some reason both of them consider `NameError` a subclass of this!

Why do they do all this? And are there dynamic languages that don't?

contact

subscribe via RSS