> On 15 Oct 2019, at 00:02, Leal Duarte <ajldua...@sapo.pt> wrote:
>
> yoption trycatch;
>
> default
> {
> state_entry()
> {
> llSay(0, "Script running");
> }
> touch_start(integer nn)
> {
> try
> {
> osSetTerrainHeight(120, 100, 30);
> llSay(0,"terrain done ");
> }
> catch (exception ex)
> {
> PrintOutException (ex);
> }
> finally
> {
> llSay(0,"finally ");
> }
> }
> }
>
> PrintOutException (exception ex)
> {
> llOwnerSay (" typename: " + xmrExceptionTypeName (ex));
> llOwnerSay (" message: " + xmrExceptionMessage (ex));
> llOwnerSay (" stacktrace:\n" + xmrExceptionStackTrace (ex));
> }
This is pretty much ideal, is it fully implemented in this form?
For lightweight scripting I'd say that being able to catch specific exception
types is arguably overkill, and if you just use a plain (no parameter) catch
then you don't really need a finally block either. For example, a simplified
form is capable enough for many use cases:
default {
state_entry() {
llSay(0, "Script running");
}
touch_start(integer x) {
try {
osSetTerrainHeight(120, 100, 30);
llSay(0, "terrain done");
} catch {
llSay(0, "terrain failed');
}
llSay(0, "finally");
}
}
This makes sense if we assume the goal of try in an LSL script is to prevent
the script from halting at all, which differs from normal try/catch in
programming where it's usually more about logging errors or presenting error
messages before halting anyway (or exiting gracefully instead). I suppose part
of the problem is that the halting behaviour of OSSL functions is weird because
it's halting a script due to a problem that isn't really the script's fault,
but the region's.
The behaviour is strange because it's different from permissions errors (e.g-
animating an avatar without asking permission first) which produces an error
but doesn't halt the script, but it means that the purpose of try/catch is
slightly different to other languages in which it is commonly used I think.
In terms of simplification, if you don't actually need to handle the error
case, then if catch blocks were optional this could be simplified even further:
default {
state_entry() {
llSay(0, "Script running");
}
touch_start(integer x) {
try { osSetTerrainHeight(120, 100, 30); }
llSay(0, "finally");
}
}
That seems pretty neat to me; if you need to know if a function succeeded you
can still do:
default {
state_entry() {
llSay(0, "Script running");
}
touch_start(integer x) {
integer terrain_set = FALSE;
try { osSetTerrainHeight(120, 100, 30); terrain_set = TRUE; }
llSay(0, "finally");
if (terrain_set) { /* Put it back to normal? */ }
}
}
_______________________________________________
Opensim-dev mailing list
Opensim-dev@opensimulator.org
http://opensimulator.org/cgi-bin/mailman/listinfo/opensim-dev