YENGtry

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
Line 8: Line 8:
  
  
a try block must be follow by at least one catch or one finally block
+
a try block must be follow by at one catch, one finally block or both
  
 
<div style="background-color:#FFA500; padding:10px; padding-bottom:5px; border: 1px #FF544F solid">
 
<div style="background-color:#FFA500; padding:10px; padding-bottom:5px; border: 1px #FF544F solid">
Line 39: Line 39:
 
       llSay(0,"finaly");
 
       llSay(0,"finaly");
 
     }
 
     }
 +
}
 +
 +
detect no ossl permission
 +
 +
touch_start(integer nn)
 +
{
 +
    try
 +
    {
 +
        key agent = llDetectedKey(0);
 +
        osForceOtherSit(agent);
 +
    }
 +
    catch(exception ex)
 +
    {
 +
        string message = yExceptionMessage(ex);
 +
        if(osStringStartsWith(message,"ossl permission error", TRUE))
 +
            llSay(0,"You need to enable  osForceOtherSit on osslEenable.ini");
 +
        else
 +
            throw;
 +
    }
 
  }
 
  }

Revision as of 17:30, 19 September 2020

try, catch and finally allow to handle some exceptions without getting the script killed.

  • on the try block we place the code we want to run protected.
  • on the catch block place code to handle the exception
  • on the finally block we place code that should run always.
  • throw keyword allows a catch to reissue the exception, so the engine handles it normaly


a try block must be follow by at one catch, one finally block or both

at this time catch must be in form catch(exception ex) {...} and exception type detected by the exception message, this maybe improved in future


There can not be any llResetScript or osResetAllScripts inside any of this blocks. script will compile but fail with a severe runtime error


silly example

touch_start(integer nn)
{
   integer a = 0;
   try
   {
      llSay(0,"try");        
      float c = 1 / a;
   }
   catch(exception ex)
   {
       if(yExceptionMessage(ex) == "Division by Zero")
          llSay(0,"Where did you learn math?");
       else
        throw;
   }
   finally
   {
      llSay(0,"finaly");
   }
}

detect no ossl permission

touch_start(integer nn)
{
    try
    {
       key agent = llDetectedKey(0);
       osForceOtherSit(agent);
    }
    catch(exception ex)
    {
        string message = yExceptionMessage(ex);
        if(osStringStartsWith(message,"ossl permission error", TRUE))
           llSay(0,"You need to enable  osForceOtherSit on osslEenable.ini");
        else
           throw;
    }
}
Personal tools
General
About This Wiki