@hogi It would be a game changer if there would a better error handling as I have proposed in a Wishlist entry. The error handling is at least in 17.1 not unique and not well documented. As it is now ( and I think in 18.2 as well) there seem to be two different forms of error messages in exception_msg() available which are also not documented in the Scripting Index nor in any other documentation.
Error message should also be language-independent to check for in error handling or should have a kind of unique error code which can be checked for in an error routine. This could look as follows:
try (
<some action>
,
// we have to check for the exact message in all languages to handle a specific error:
If (error_msg()[1] == "File not found" || error_msg()[1] == "Datei wurde nicht gefunden",
// better would it be to have a language independent code
// If (error_code() == 93 or better: ...== error_code["FileNotFound"]
print("File not found: ");
<do something because file was not found>
,
...
);
);
The Open function returns currently an error message as a list entry with additional arguments:
try(
open ("table");
,
Show(exception_msg());
//
// Returns in german language setting
// exception_msg() = {"Tabelle kann nicht geöffnet werden"(1, 2, "Open", Open /*###*/("table"))};
//
// Returns in english
// exception_msg() = {"Cannot open table"(1, 2, "Open", Open /*###*/("table"))};
);
Neither of these arguments are anywhere documented or I have not yet found this.
In my opinion it would be nice to have a error object (in a class format) returned that has all information about the error e.g. :
try( <action>
,
if (exception() << code == exception.FILENOTFOUND,
Print( exception() << message );
...
Then there is the throw function which is nice but does not seem to support the arguments used in the exception_msg(). It would be nice if any argument values could be handed over to the error handling routine.
try(
throw("Error"(1,2));
,
Show (exception_msg());
// Arguments to the thrown "Error" are lost.
);
As a conclusion the error handling could be more improved. I would appreciate it if the error handling gets these improvements.