The only way to get feedback in the catch expression of a JSL try() function is through the Exception_msg variable, but that variable is not always set to a useful value. Sometimes it is. You can use the JSL throw() function to set it, like this:
try( print("hello"); throw("bang!"), show(exception_msg))
"hello"
exception_msg = "bang!";
So you could wrap other JSL that might create an exception with something like this:
myOpen = function({file},
try(open(file),
throw("could not open "||file|| " details="||char(exception_msg)))
);
try( myopen("NOSUCHFILE.JMP"), show(exception_msg) );
exception_msg = "could not open NOSUCHFILE.JMP details=.";
Open didn't set the exception_msg (no details, above), but sqrt(string value) does (extra details, below):
mysqrt = function({v},
try(sqrt(v),
throw("could not sqrt "||v|| "\!ndetails="||char(exception_msg)))
);
try( mysqrt("minus one"), write(exception_msg) );
could not sqrt minus one
details={"Cannot convert argument to a number [or matrix]"(1, "Sqrt", Sqrt /*###*/(v))}
So you don't really need a wrapper for sqrt. By concatenating the possible exception_msg to your own, more illuminating message, you'll get more details if open is enhanced to return the exception message in the future. The char() function around the exception_msg converts a non-existent message to a valid string for concatenation.
Craige