Runtime exceptions

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Minor English improvements)
Line 1: Line 1:
When a error is detected while executing a program, like a division by zero, access to a invalid memory location, etc, most languages provide a way define code to try to handle them.<br>
+
When error are detected while executing a program, like a division by zero, access to an invalid memory location, etc., most languages provide a way to define code to try to handle them.
 +
 
 +
.<br>
 
Default action is usually to issue a message and kill the program.<br>
 
Default action is usually to issue a message and kill the program.<br>
.Net (the enviroment OpenSimulator runs on) creates a block of data (a class object) called Exception, with information about what happened and where.<br>
+
.Net (the enviroment OpenSimulator runs on) creates a block of data (a class object) called an <em>Exception</em>, with information about what happened and where.<br>
The runtime control code aborts current execution and looks if the code path been executed is inside a try block. If there are catch blocks after if, the runtime calls them with that Exception as argument, so their code can try to handle it, preventing the program to just die.<br>
+
The runtime control code aborts current execution and looks if the code path being executed is inside a <em>try</em>block. If there are <em>catch</em> blocks after it, the runtime calls them with the Exception as argument, so their code can try to handle it, preventing the program from just a die.<br>
There can be derivatives types of Exception, to make more clean the problem, and even include more specific information.<br>
+
There can be derivative types of Exception, to make more clear the problem, and even allow the inclusion of more specific information.<br>
A catch can be made only sensitive to that type by just declaring it using that type name as argument:<br>
+
A catch can be made only sensitive to a specific type of exceotion by just declaring it using the type name as argument:<br>
 
  catch(exceptionTypeName ex)
 
  catch(exceptionTypeName ex)
Using this mechanism, programs can also create their own types and issue (throw) them when there is a need to abort execution, and go back to a relevant catch{} block.
+
Using this mechanism, programs can also create their own types and issue (<em>throw</em>) them when there is a need to abort execution, and go back to a relevant catch{} block.
 
This is for example how llResetScript stops the script execution and goes back to control, that then does the reset.
 
This is for example how llResetScript stops the script execution and goes back to control, that then does the reset.
  
 
On YEngine lower case in used for exception names, and it only knows 2 types, for now.
 
On YEngine lower case in used for exception names, and it only knows 2 types, for now.
 
* exception ( ie .net Exception) means any kind of Exception a script can be allowed to intercept.
 
* exception ( ie .net Exception) means any kind of Exception a script can be allowed to intercept.
* scriptexception (.net ScriptException) a exception issued by the scripts supporting code.
+
* scriptexception (.net ScriptException) an exception issued by the script's supporting code.
  
most relevant cases for scripts will be type scriptexception.<br>
+
Most relevant cases for scripts will be of type scriptexception.<br>
note that scriptexception and any other exception types are also exception (they derive from it), so a catch(exception ex) will be triggered by it.<br>
+
Note that scriptexception and any other exception types are also an exception (they derive from it), so a catch(exception ex) will be triggered by it.<br>
 
<br>
 
<br>
  
This limited set is because the scripts support code was made for XEngine, and needs to support it. For example a division by zero could just be the .net DivideByZeroException, instead it is converted into scriptexception.
+
This limited set of exception types is because the scripts support code was made for XEngine, and needs to support it. For example a division by zero could just be the .net DivideByZeroException, instead it is converted into scriptexception.
so we need to look to the exception message to identify what they really are.
+
So we need to look to the exception message to identify what they really are.
Note that this limited set also makes life easier for YEngine scripts error handling, so not really a XEngine limitation.
+
Note that this limited set also makes life easier for YEngine scripts error handling, so is not really a XEngine limitation.

Revision as of 07:52, 21 September 2020

When error are detected while executing a program, like a division by zero, access to an invalid memory location, etc., most languages provide a way to define code to try to handle them.

.
Default action is usually to issue a message and kill the program.
.Net (the enviroment OpenSimulator runs on) creates a block of data (a class object) called an Exception, with information about what happened and where.
The runtime control code aborts current execution and looks if the code path being executed is inside a tryblock. If there are catch blocks after it, the runtime calls them with the Exception as argument, so their code can try to handle it, preventing the program from just a die.
There can be derivative types of Exception, to make more clear the problem, and even allow the inclusion of more specific information.
A catch can be made only sensitive to a specific type of exceotion by just declaring it using the type name as argument:

catch(exceptionTypeName ex)

Using this mechanism, programs can also create their own types and issue (throw) them when there is a need to abort execution, and go back to a relevant catch{} block. This is for example how llResetScript stops the script execution and goes back to control, that then does the reset.

On YEngine lower case in used for exception names, and it only knows 2 types, for now.

  • exception ( ie .net Exception) means any kind of Exception a script can be allowed to intercept.
  • scriptexception (.net ScriptException) an exception issued by the script's supporting code.

Most relevant cases for scripts will be of type scriptexception.
Note that scriptexception and any other exception types are also an exception (they derive from it), so a catch(exception ex) will be triggered by it.

This limited set of exception types is because the scripts support code was made for XEngine, and needs to support it. For example a division by zero could just be the .net DivideByZeroException, instead it is converted into scriptexception. So we need to look to the exception message to identify what they really are. Note that this limited set also makes life easier for YEngine scripts error handling, so is not really a XEngine limitation.

Personal tools
General
About This Wiki