3 ms·
I love that example of the lua error message, but aren't there non-arithmetic functions that also error? What's the message in that case? What's nice about Pyt
by gugagore 6y ago
I love that example of the lua error message, but aren't there non-arithmetic functions that also error? What's the message in that case?
What's nice about Python's message is how compositional or "orthogonal" it is, which means that the errors can easily be handled in a program. Does Lua have anything like that? From the manual
> If you need to handle errors in Lua, you should use the pcall function (protected call) to encapsulate your code.
This actually helps me understand a bit the dichotomy between "configuration" and "program", and why Lua is so good for the former. As another comment put it, it's good when you need to "describe stuff". It doesn't make a lot of sense to describe something that handles errors in its own description, which motivates relegating error handling to specific contexts.
- BugsJustFindMe 6y ago> aren't there non-arithmetic functions that also error? What's the message in that case? Any function can error in any way imaginable, but if we're talking about built-ins... `print(nil.."a")` -> "attempt to concatenate a nil value" `print(({}).foo.bar)` -> "attempt to index a nil value (field 'foo')" `table.insert(a, 1)` -> "bad argument #1 to 'insert' (table expected, got nil)" On the Python side you get: `None[1]` -> "TypeError: 'NoneType' object is not subscriptable" `str.split(None, "d")` -> "TypeError: descriptor 'split' for 'str' objects doesn't apply to a 'NoneType' object"