Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The separation between the mainline logic and the exception handling logic does not require an exception mechanism like in Java or C++.

A restricted form of GOTO, like in the language Mesa (from Xerox) is good enough.

Mesa also had exceptions for things where exceptions are appropriate, e.g. numeric overflow, out-of-bounds access or memory allocation errors, i.e. errors that are normally caused by program bugs and which can be solved only by someone who knows the internals of the program.

For errors whose cause can be determined and removed by the user, e.g. files that cannot be found or mistyped user input, the appropriate place of handling the error is the place where the function that failed had been invoked.

Neither inside the function that failed nor several levels above the place where the error has been detected it is possible to provide really informative error messages that can enable corrective action, because only at the place of invocation the precise reason is known why the failed function had been called.

The restricted GOTO from Mesa, whose purpose was error handling, could not jump backwards and it could not enter a block, which eliminated the possible abuses of the feature.

Moreover the labelled targets of the GOTO could exist only inside a delimited section at the end of a block.

The keyword GOTO is not needed, because it is redundant. At the place of the jump it is enough to write the target label, as no other action is possible with it.

So in a language like Mesa, the mainline logic would be something like (in languages with "then", no parentheses are needed, unlike in C and its followers):

if err_code := function_that_can_fail(...) then Error_Name

if err_code := function2_that_can_fail(...) then Error2_Name

and the error handlers will be grouped in a section similar with the error handlers used with the exception mechanism of Java or C++.

The difference is that the section with the error handlers must be in the same file with the function invocations that can return errors and the error handlers will be invoked only from there, not from random places inside who knows what 3rd party library might have been used somewhere.

Because for such handlers there is no COME-FROM problem, you know exactly what has happened and you can easily determine what must be done.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: