When the following code is run:
(function recur() {
recur()
})()
the following error is raised —
Uncaught RangeError: Maximum call stack size exceeded
— with the stack filled with references to the function (recur
).
So why does the following code:
(function recur() {
try {
recur()
} catch (error) {
recur()
}
})()
even though the error is caught in the try
block, not return the error in the catch
block? Or at least complain about the function overflowing the call stack?
When the code is run, it does pause all other non-asynchronous code from executing, but still... no errors?! What's going on here?
EDIT:
This behavior is especially weird with code like this:
(function notRecur() {
try {
Symbol() + 2
} catch (error) {
Symbol() + 2
}
})()
that returns a TypeError
when executed.
Just another question to experiment with, thanks for reading through and replying.