LOTUSSCRIPT-SPRACHE
The error model
The Java error model is catch and throw. The LotusScript error model is the ON ERROR statement and the error handling block. LotusScript catches the Java error and maps it to its error processing model. This allows the LotusScript user to manipulate the Java error with LotusScript error semantics through the use of the JavaError class.
The user should look at the LotusScript Error before the JavaError properties. If an error is trapped within LotusScript before Java is called, JavaError.ErrorMsg and JavaError.StackTrace are empty strings. Note the following code:
Uselsx *javacon
Sub Initialize
Dim jSession As JavaSession
Dim cls As JavaClass
Dim obj As JavaObject
Dim msg As String
Dim jError As JavaError
On Error Goto ErrorHandling
Set jSession = New JavaSession()
Set cls = jSession.GetClass("java/lang/Short")
' This signature would not match any Constructor
Set obj = cls.CreateObject("(X)V", 1)
Print obj.toString()
Exit Sub
ErrorHandling:
Print Error ' "LS2J Error: Constructor failed to execute"
Set jError = jSession.getLastJavaError
Print "Java error: " jError.ErrorMsg ' empty String
End Sub
The user attempts to call the java.lang.Short Constructor. The correct call is the signature for a short parameter:
Set obj = cls.CreateObject("(S)V", 1)
Instead the user calls the following:
Since "X" doesn't match any Java type, LotusScript raises an error before calling Java. The only error message is in the LotusScript error:
LS2J Error: Constructor failed to execute
If the LotusScript portion of LS2J cannot detect an error, it calls Java. Suppose the code reads:
Set obj = cls.CreateObject("(I)V", 1)
This signature could match a Constructor with an int parameter. LotusScript detects no error; attempts to call the Java Constructor, and fails because the java.lang.Short class has no Constructor with an int parameter. The LotusScript Error is still:
But because Java was called, there is also a jError.ErrorMsg:
java.lang.NoSuchMethodError: <init>
The JavaError object, when retrieved from the JavaSession, contains the last error and the last StackTrace.
Example code using JavaError
Dim mySession As New JavaSession
Dim myError As JavaError
On Error GoTo ErrorHandling
'...
' code here
'....
Set myError = mySession.getLastJavaError
print Error
print myError.ErrorMsg
print myError.StackTrace
This code sample prints the LotusScript error, the Java error, and the Java StackTrace.
Examples of LotusScript errors that might be misunderstood
Example 1:
You try to instantiate an object, but you have the wrong signature or number of arguments.
Example 2:
You try to instantiate an object, but an error occurs in the Constructor.
at myGraph.<init>(Compiled Code)
Example 3a:
You try to execute a method, but use the wrong number of arguments.
Example 3b:
Now, you execute the method with the right arguments but there is an error in the method.
at myGraph.setOrientation(myGraph.java:262)
Siehe auch