Errors and error handling Clause Samples
Errors and error handling. Some of the microscopes functions may return (raise) an error. This can happen due to a physical reason, i.e. if the requested action is not possible at that moment. For example, you cannot ask the stage to perform a GoTo(), when it is wobbling or already moving. The high tension may not be switched on or raised under certain conditions and so forth. You may also have given parameters that are out of range (in that case the stage for example would not move either). Generally, calls to another process (from your script to the TEM server) may fail occasionally. There are also some failures that may be VisualBasic-specific (see below). So be aware and do the error handling - otherwise your script might die! If an error is raised, then a global Error object (Err) will be filled with detailed information about the error, if available. You can use this information for your error handling. Usually you will get an error code (a number), a textual description and maybe a text string with the name of the source that raised the error. The following piece of code gives an example: (Suppose you have a form with at least a button named ‘cmdGoto’ and a textbox named ‘txtDisplay’. As reaction on a button-click a new stage position is calculated -just as an example, you could invent some code here- and the stage is requested to move to that position. In case of an error the content of the error object is shown in the textbox): Private Sub cmdGoto_Click() Dim NewPos as TEMScripting.StagePosition Dim OldPos as TEMScripting.Stageposition Dim MyStage as TEMScripting.Stage On Error GoTo ComError: Set MyStage = MyTem.Stage Set OldPos = MyStage.Position CalculateNewPosition OldPos, NewPos MyStage.Goto NewPos, axisXY Exit Sub ComError: txtDisplay.Text = _ txtDisplay.Text & "Error # " & Hex(Err.Number) & _ " was generated by " & Err.Source & vbCrLf _ & Err.Description & vbCrLf txtDisplay.SelStart = Len(txtDisplay.Text) End Sub At the end of the error handling you can either do nothing (as in the above example), that is leave the function or add either Resume which jumps back to the line in your code where the error occurred or Resume Next which jumps back to the next line in your code Goto MyLabel jump to a specified label, here named MyLabel. Another possibility is to use the On Error Resume Next ... On Error Goto 0 statements. This allows you either to ignore errors or ask for the contents of the Err object after each relevant statement and do the error handling ‘in place’. If yo...
Errors and error handling. Some of the microscopes functions may return (raise) an error. This can happen due to a physical reason, i.e. if the requested action is not possible at that moment. For example, you cannot ask the stage to perform a GoTo_, when it is wobbling or already moving. The high tension may not be switched on or raised under certain conditions, and so forth. You may also have given parameters that are out of range (in that case the stage for example would not move either). Generally, calls to another process (from your script to the TEM server) may fail occasionally. So be aware and do the error handling, typically by a try except end; If an error is raised, then Exception.Message will be filled with detailed information about the error, if available. You can use this information for your error handling. See the error handling in the code examples above.
Errors and error handling. Some of the microscopes functions may return (raise) an error. This can happen due to a physical reason, i.e. if the requested action is not possible at that moment. For example, you cannot ask the stage to perform a GoTo(), when it is wobbling or already moving. The high tension may not be switched on or raised under certain conditions and so forth. You may also have given parameters that are out of range (in that case the stage for example would not move either). Generally, calls to another process (ie from your script to the TEM server) may fail occasionally. So be aware and do the error handling - otherwise your application might die! If an error is raised, then a global Error object (Err) will be filled with detailed information about the error, if available. You can use this information for your error handling. Usually you will get an error code (a number), a textual description and maybe a text string with the name of the source that raised the error. If you want to do the error handling, you have to insert the following statement into the code: On Error Resume Next This statement makes VBScript ignoring errors and is valid for the code to follow until the end of the function or subroutine. You then got the chance to ask the error object for its content. An example: Suppose your HTML page contains a form with a button named ‘cmdGoto’, and a text area named ‘TextErrors’. Pressing the button triggers movement of the stage to a new position that is calculated from the old one -just as an example, you could invent some code here: <FORM ID="theForm"> ... <INPUT TYPE=BUTTON NAME="cmdGoto" VALUE="Go" ONCLICK="OnGoto()">
