Autor Thema: [LS-Optimierung] Resume Next und Errorhandling  (Gelesen 10756 mal)

Offline TMC

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 3.660
  • Geschlecht: Männlich
  • meden agan
[LS-Optimierung] Resume Next und Errorhandling
« am: 14.10.04 - 00:17:26 »
Ausgangs-Thread siehe hier:
http://www.atnotes.de/index.php?topic=18753.0

U.a. geht es darum:
a) Wann macht es Sinn, Resume Next zu verwenden (generell)
b) Wie beendet man eine Error-Routine.

Zu (b) waren folgende Vorschläge genannt:

1.) per Exit Sub / Exit Function

2.) per Resume:
Code
Sub Demo
On Error Goto ErrHandler
... hier der Code
ExitCode:
   Exit Sub

ErrHandler:
  Print "Es ist ein Fehler aufgetreten"
  Resume ExitCode
End Sub

(Details wie gesagt im obigen Thread).

U.a. folgende Vorteile zu (2) wurden genannt:

 - mit dem Exit Sub im Error-Handler wird eines der strengen Gesetze der modularen Entwicklung durchbrochen: dadurch gibt es mehrere Ausstiegspunkte aus dem Modul
 - den "ExitCode" - Teil kann man auch innerhalb des Scriptes anspringen wenn man abbrechen will (z.B. in einer Msgbox), Vorteil: wenn man z.B. die Sub zu einer Function umwandeln will, muss man nur an wenigen Stellen Code ändern
 - Evtl. muss man außerdem noch was vor dem Exit erledigen, was global gilt, dann kann man das auch in das "ExitCode" integrieren


Eure Erfahrungen?
Matthias

A good programmer is someone who looks both ways before crossing a one-way street.


Offline koehlerbv

  • Moderator
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 20.460
  • Geschlecht: Männlich
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #1 am: 14.10.04 - 00:28:17 »
Gehört das Thema nicht eher zur BP-Diskussion ? Das hat ja nix mit speziell mit R6 zu tun, sondern gilt auch in 4, 5 und 7.
Mal so als kleiner Verweis zu
http://www.atnotes.de/index.php?topic=18819.20

Und mal sehen, was mit den Links passiert, wenn das Thema nun verschoben wird. Schönes Beispiel ...

Bernhard

Offline Semeaphoros

  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 8.152
  • Geschlecht: Männlich
  • ho semeaphoros - agr.: der Notesträger
    • LIGONET GmbH
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #2 am: 14.10.04 - 07:12:48 »
Bin auch der Meinung, dass das in die BP-Diskussion hineingehört.
Jens-B. Augustiny

Beratung und Unterstützung für Notes und Domino Infrastruktur und Anwendungen

Homepage: http://www.ligonet.ch

IBM Certified Advanced Application Developer - Lotus Notes and Domino 7 und 6
IBM Certified Advanced System Administrator - Lotus Notes and Domino 7 und 6

Offline Axel

  • Moderator
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 8.658
  • Geschlecht: Männlich
  • It's not a bug, it's Notes
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #3 am: 14.10.04 - 08:17:58 »
Hi,

sehe ich genauso. Das passt am besten in die BP-Diskussion. dort wurde das Thema Error-Handling doch schon behandelt.

Axel
Ohne Computer wären wir noch lange nicht hinterm Mond!

Offline TMC

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 3.660
  • Geschlecht: Männlich
  • meden agan
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #4 am: 14.10.04 - 21:38:09 »
Da habt Ihr natürlich vollkommen Recht, dass dies in BP gehört. Ich habe ohne weiter nachzudenken diesen Thread eröffnet.
Ich PeEmme mal einen Mod dieses Forums an (falls von Euch noch nicht geschehen).

Nichtsdestotrotz darf natürlich jeder soweit schonmal seine Erfahrungen, Vorschläge etc. hier posten  :D

Insbesondere Bernhard hat ja schon im anderen Thread angekündigt, hier dann was zu posten...
« Letzte Änderung: 14.10.04 - 21:41:05 von TMC »
Matthias

A good programmer is someone who looks both ways before crossing a one-way street.


Glombi

  • Gast
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #5 am: 14.10.04 - 21:46:22 »
Resume Next verwende ich äußerst selten.
Ein Anwendungsfall: Man will in allen Dokumenten einer Datenbank ein neues Feld setzen. Man weiß aber nicht, ob man alle Dok. bearbeiten kann.

Dann so

set dc = db.AllDocuments

On Error Resume Next
set doc = dc.GetFirstDocument
 doc.NeuesFeld = "wert"
 call doc.Save(true,true,true)  'hier kann es zum Fehler kommen
set doc = dc.GetNextDocument(doc)

Wenn man ein Dokument nicht bearbeiten kann, geht es halt zum nächsten.
Die nicht geänderten kann man sich dann über eine Ansicht herausfiltern.

Andreas

Offline TMC

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 3.660
  • Geschlecht: Männlich
  • meden agan
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #6 am: 14.10.04 - 21:52:37 »
Das mit dem Feld-Setzen oder Löschen von Dokumenten (alle, selektierte etc.) habe ich auch schon so über Resume Next gemacht.
Fand ich da auch sehr praktisch, wenn der User nicht darf, wird einfach weitergemacht.

Ich hatte das da noch ein wenig verfeinert und bei diesem Scriptteil ein On Error goto SAVEERROR gesetzt (und danach wieder zurückgesetzt zu on error goto ErrorHandler).
Im SAVEERROR ist dann vor dem "Resume Next" noch ein intCount = intCount - 1 (um zu Zählen wieviele Doks tatsächlich bearbeitet wurden).
Matthias

A good programmer is someone who looks both ways before crossing a one-way street.


Glombi

  • Gast
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #7 am: 16.10.04 - 10:28:13 »
Resume Next ist u.a. auch in der R6 Mailschablone im Agenten (ImportHolidays) zu finden:

Set doc = m_dbCurrentDatabase.GetDocumentByUNID(APPTUNID)  '  if its not there - needs fixup
On Error 4091 Resume Next
If (doc Is Nothing) Or (doc.Size <= 0) Then   ' doc size of zero means its a ghost doc

Interessant auch
Zitat
(doc.Size <= 0) Then   ' doc size of zero means its a ghost doc

Das fange ich bisher so nicht ab. Was ist ein ghost doc? Soft Delition?

Andreas

Offline TMC

  • Freund des Hauses!
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 3.660
  • Geschlecht: Männlich
  • meden agan
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #8 am: 16.10.04 - 10:42:07 »
Interessant auch
Zitat
(doc.Size <= 0) Then   ' doc size of zero means its a ghost doc
Das fange ich bisher so nicht ab. Was ist ein ghost doc? Soft Delition?

Ich kenne das im Kontext von einer UnprocessedDocuments Collection, da hatte manchmal als Rückgabe Deletion Stubs. Die Abfrage nach der Größe (also If (doc.Size = 0) Then .....) lässt diese dann rausfiltern.
Was da allerdings das "<" - Zeichen soll ist mir nicht klar. Scheinbar gibt es negative Dokumentgrößen  ;D
Matthias

A good programmer is someone who looks both ways before crossing a one-way street.


Offline Semeaphoros

  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 8.152
  • Geschlecht: Männlich
  • ho semeaphoros - agr.: der Notesträger
    • LIGONET GmbH
Re: [LS-Optimierung] Resume Next und Errorhandling
« Antwort #9 am: 16.10.04 - 15:12:21 »
Also, Deletion Stubs sollte man eigentlich über IsValid oder IsDeleted abfangen. Ghost-Document würde ich meinen, ist ein existierendes Dokument, das keinen wirklichen Inhalt hat, woher die dann aber kommen könnten, müsste man sich schon fragen, sieht nach einem Workaround aus
Jens-B. Augustiny

Beratung und Unterstützung für Notes und Domino Infrastruktur und Anwendungen

Homepage: http://www.ligonet.ch

IBM Certified Advanced Application Developer - Lotus Notes and Domino 7 und 6
IBM Certified Advanced System Administrator - Lotus Notes and Domino 7 und 6

Glombi

  • Gast
Was ist ein ghost document
« Antwort #10 am: 16.10.04 - 15:21:49 »
Laut KBASE ist ein "ghost document" ein gelöschtes Hauptdokument, zu dem es eine Antwort gibt.

Hier der Artikel:
Problem
The ParentDocumentUNID property (of the NotesDocument class), when used in conjunction with the GetDocumentByUNID method (of the NotesDatabase class), allows you to get a handle to a response document's parent document. 

If the parent document of the response document (also known as a child document) has been deleted, the response document is considered an orphan.  The deleted parent document is considered a ghost.

When you use the GetDocumentByUNID method to attempt to get a handle to the parent of an orphan, an error usually occurs.  The actual text of the error, however, varies depending on the version of Notes.  Furthermore, certain Notes releases do not generate an error.

Below is a sample script.  When you run this script in various Notes 4.x releases, the results are different.

Sample Script:

Sub Initialize
     Dim session As New notessession
     Dim cdoc As notesdocument
     Dim pdoc As notesdocument
     Dim db As notesdatabase
     Dim view As notesview
     
     Set db=session.currentdatabase
     Set view=db.getview("Parent and Child")
     
     Set cdoc=view.getfirstdocument
     While Not (cdoc Is Nothing)
            If cdoc.isresponse Then
                 Set pdoc=db.getdocumentbyUNID(cdoc.parentdocumentUNID)
               ' Attempting to access the parent of an orphan, above, will cause an error in most Notes releases 
            End If
           Set cdoc=view.getnextdocument(cdoc)
     Wend
End Sub




Below is a breakdown of how the different Notes 4.x releases react when you attempt to get a handle to the parent of an orphan document:

Notes 4.1x:

A handle to the document is returned but attempting to access any of the document's properties results in the following error:

"Notes error: Document has been deleted"

The error number associated with this message is 4000.

Notes 4.5x (except Notes 4.5.4a):

The following error results:

"Notes error: Document has been deleted (<ParentDocumentUNID>)"

The error number associated with this message is 4005.

Notes 4.6, 4.6a, 4.6.2x & 4.6.3x:

The following error results:

"Invalid universal ID"

The error number associated with this message is 4091.


Notes 4.5.4a, Notes 4.6.1x, Notes 4.6.4x and higher (including Notes 5.0):

No error occurs.  You get a handle to the ghost (deleted parent) document.  You can perform a check to determine whether the Size property of the returned document handle is greater than zero to verify whether the parent document has been accessed.


It is actually this behavior that is most appropriate.  Although the parent document has been deleted, it still has children, and it is most appropriate for Notes to keep a shell of the parent around as a placeholder (to help keep track of the children). 

Conclusion:

If you need to code error handling to deal with the various possible outcomes, you must check for errors 4005, 4091 (for releases 4.5x, 4.6, 4.6a, and 4.6.2x) and error 4000 (which occurs when you attempt to access a document property in 4.1x).  You must also check if the Size property equals zero (to check for 4.5.4a, 4.6.1x, 4.6.3 and up).  Note:   Error codes can change from release to release and thus will not necessarily be the same going from one release to another.

The code below demonstrates provides one way this can be done.  An 'On Error' statement is used to route control of the code if an error occurs.  The error handling section checks whether the error is one of those expected, and resumes the code such that it gets the next document.  If an error is not encountered, the code verifies that the document handle is not for a 'ghost' document (by checking the size).

Sample Script:

Sub Initialize
     Dim session As New notessession
     Dim cdoc As notesdocument
     Dim pdoc As notesdocument
     Dim db As notesdatabase
     Dim view As notesview
     
     Set db=session.currentdatabase
     Set view=db.getview("Parent and Child")
 
     On Error Goto errhandle     
     Set doc=view.getfirstdocument
     While Not (cdoc Is Nothing)
          If cdoc.isresponse Then
               Set pdoc=db.getdocumentbyUNID(cdoc.parentdocumentUNID)
               If pdoc.size = 0 Then               
                 ' Found orphan in 4.6.1x, 4.5.4a.  Got handle but size=0.
              End If
          End If
GetNextDoc:
          Set cdoc=view.getnextdocument(cdoc)
     Wend
     Exit Sub

ErrHandle:
     If Err=4091 Or Err=4005 Or Err=4000 Then
             ' Found orphan in 4.1x, 4.5x, 4.6x or 4.6.2x
               Resume GetNextDoc
     End If     
     Messagebox "Error # " & Cstr(Err) & ":  " & Error$
     Exit Sub
End Sub

Supporting Information:

With all Notes Releases:  When you have a handle to a parent document and mistakenly attempt to use ParentDocumentUNID with the GetDocumentByUNID method, the following error occurs:

"Invalid universal ID"

The error code associated with this message is 4091.

It is important to note that this is the same error message you receive when you attempt to access the parent of an orphan in Notes releases 4.6, 4.6a, and 4.6.2x.

One way to avoid trying to access the parent of a document that is actually a parent itself is to use the IsResponse property (of the NotesDocument class).  This methodology is utilized in the Conclusion section of the technote.

Related Documents:

How to Find Orphan Documents
Document #:  113861

Andreas

 

Impressum Atnotes.de  -  Powered by Syslords Solutions  -  Datenschutz