OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Sub or Function in errorHandler

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
lesguilw
Power User
Power User


Joined: 09 Nov 2005
Posts: 57
Location: Frenchy in Sevilla, Spain

PostPosted: Fri Oct 20, 2006 1:09 am    Post subject: Sub or Function in errorHandler Reply with quote

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
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1145
Location: France

PostPosted: Fri Oct 20, 2006 3:08 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
lesguilw
Power User
Power User


Joined: 09 Nov 2005
Posts: 57
Location: Frenchy in Sevilla, Spain

PostPosted: Fri Oct 20, 2006 4:37 am    Post subject: Reply with quote

Now it works! Thank you very much, I was going mad with this problem Evil or Very Mad
Back to top
View user's profile Send private message
TerryE
Super User
Super User


Joined: 16 Jul 2006
Posts: 554
Location: UK

PostPosted: Fri Oct 20, 2006 3:26 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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