| View previous topic :: View next topic |
| Author |
Message |
lesguilw Power User

Joined: 09 Nov 2005 Posts: 57 Location: Frenchy in Sevilla, Spain
|
Posted: Fri Oct 20, 2006 1:09 am Post subject: Sub or Function in errorHandler |
|
|
Hi,
I want to insert a function in my errorHandler but something weird happens: when I trigger the sub containing the errorHandler, on error I get to the IDE (when I shouldn't), the function in the errorHandler is highlighted as if it was causing an error but no error message is displayed, and the function doesn't start.
Here is the code, do you see something wrong?
| Code: |
exit sub
errorHandler:
plantillasError(Err, Erl, Error$, "OpenDocument")
End Sub
Sub plantillasError(byVal errorNum, byVal errorLine, byVal errorString, byVal func, optional comment as string)
'Crea el dialog de error
If (Not GlobalScope.DialogLibraries.LoadLibrary("PlantillasSP")) Then
DialogLibraries.LoadLibrary("PlantillasSP")
End If
oDlgError = CreateUnoDialog(DialogLibraries.PlantillasSP.dlgError)
'Construye mensage de error
errorMessage = "Error: " & Err & ", line " & Erl & " en " + func + ". " & Error$
oDlgError.Model.txtError.Text = errorMessage
oDlgError.Execute()
End Sub
|
William |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1145 Location: France
|
Posted: Fri Oct 20, 2006 3:08 am Post subject: |
|
|
When you have an error you should, as quick as possible, execute a Resume instruction to clear the error condition, and then change the current error handler. If you don't do this, if another error occurs Basic stops.
In your code you enter lots of instructions while the error condition is pending.
Suggestion example for code: | Code: | errorHandler:
errorMessage = "Error: " & Err & ", line " & Erl & " en " + "OpenDocument" + ". " & Error$
Resume Label1 ' clear error condition
Label1:
On Error GoTo 0 ' reset to ordinary Basic error handler
plantillasError(errorMessage)
End Sub |
|
|
| Back to top |
|
 |
lesguilw Power User

Joined: 09 Nov 2005 Posts: 57 Location: Frenchy in Sevilla, Spain
|
Posted: Fri Oct 20, 2006 4:37 am Post subject: |
|
|
Now it works! Thank you very much, I was going mad with this problem  |
|
| Back to top |
|
 |
TerryE Super User

Joined: 16 Jul 2006 Posts: 554 Location: UK
|
Posted: Fri Oct 20, 2006 3:26 pm Post subject: |
|
|
This is one area where OOoBasic works quite differently from VBA, so if you are migrating from VBA you can get quite confused. In OOB as Bernard says, the safst thing to do is to clear down the error handing state as soon as possible. You have to do this using a Resume pointing to an immediately following label.
Also don't be tempted to try the VBA trick of using On Error Resume Next then adding a test on Err following the statement that could error. OOB only sets Err etc IF you have declared an error handler. _________________ Terry
WinXPSP3, OOo 2.4.1, Ubunto 8.04 for development
Also try the Official OOo Community Forum where I mainly post now. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|