YENGtry

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
Line 15: Line 15:
 
to catch any available exception:
 
to catch any available exception:
  
<div style="background-color:#FFA500>catch(exception ex) { } </div>
+
catch(exception ex) { }
  
 
to catch script related exceptions
 
to catch script related exceptions
  
catch(scriptexception ex) { }  
+
catch(scriptexception ex) { }
  
 
in both cases particular exception must be found by the message.
 
in both cases particular exception must be found by the message.
Line 40: Line 40:
 
       float c = 1 / a;
 
       float c = 1 / a;
 
     }
 
     }
     catch(exception ex)
+
     catch(scriptexception ex)
 
     {
 
     {
 
         if(yExceptionMessage(ex) == "Division by Zero")
 
         if(yExceptionMessage(ex) == "Division by Zero")
Line 62: Line 62:
 
         osForceOtherSit(agent);
 
         osForceOtherSit(agent);
 
     }
 
     }
     catch(exception ex)
+
     catch(scriptexception ex)
 
     {
 
     {
 
         string message = yExceptionMessage(ex);
 
         string message = yExceptionMessage(ex);

Revision as of 18:10, 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 normally


a try block must be follow by at one catch or two of the following catch types, one finally block or all of those

at this time there are only 2 types of cache blocks

to catch any available exception:

catch(exception ex) { }

to catch script related exceptions

catch(scriptexception ex) { }

in both cases particular exception must be found by the message. the catch blocks types are check by the order in source, if both needed scriptexception should be first.


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(scriptexception 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(scriptexception 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