3 ms·
I don't understand how what you suggest is distinct from exceptions as we already know them. Consider function f() which calls function g() which calls functio
by barrkel 12y ago
I don't understand how what you suggest is distinct from exceptions as we already know them.
Consider function f() which calls function g() which calls function h(). So the call stack is f -> g -> h.
Suppose that h() returns to g() with an error condition. Per your description, it now returns to f() with the error condition, rather than continuing. f() in turn returns with the error condition, because the function it called had an error.
The only way I can read your suggestion is a distinction between errors caused during a subroutine call, and errors caused directly in the body of the current function (like a divide by zero or something). But these errors are quite rare; most code is composed of calls to other code. So I'm not sure what error you could have that causes immediate return which is also distinct from a the error-case for return value of the function.
- coldtea 12y ago>I don't understand how what you suggest is distinct from exceptions as we already know them. In the handling, something you catch vs something you check the return value for (e.g. with an Optional). So, it's like an (implicit) try/catch block, where the catch just returns an error value.