Sign in to follow this  
Followers 0
gcue

error handling

19 posts in this topic

i have a sample script JOS put together but i dont think it does error handling

http://www.autoitscript.com/forum/index.php?showtopic=94376&view=findpost&p=678052

if the field doesnt exist i error out, if i put in another field that exists on all addressbook entries it works =)

Share this post


Link to post
Share on other sites



here is Jos's code

;Start a session to notes
$Session = ObjCreate("Notes.NotesSession")
$Addr_db = $Session.GetDatabase ("", "names.nsf")
$Addr_view = $Addr_db.GetView("People") 
$Addr_Doc = $addr_View.GetFirstDocument
$x=0
;' check in the view
While 1
    If Not isObj($Addr_Doc) then ExitLoop
    $item = $addr_doc.GetFirstItem( "Birthday" )
    $Bday= $item.DateTimeValue
    if $bday.dateonly <> "" then 
        $user = $addr_Doc.GETFIRSTITEM("FirstName").text & " " & $addr_Doc.GETFIRSTITEM("LastName").text
        ConsoleWrite('person:' & $user & '   $bday.dateonly = ' & $bday.dateonly & @lf & '>Error code: ' & @error & @lf);### Debug Console
    EndIf
    $Addr_Doc = $Addr_view.GetnextDocument($Addr_Doc)
Wend

Share this post


Link to post
Share on other sites

here is Jos's code

;Start a session to notes
$Session = ObjCreate("Notes.NotesSession")
$Addr_db = $Session.GetDatabase ("", "names.nsf")
$Addr_view = $Addr_db.GetView("People") 
$Addr_Doc = $addr_View.GetFirstDocument
$x=0
;' check in the view
While 1
    If Not isObj($Addr_Doc) then ExitLoop
    $item = $addr_doc.GetFirstItem( "Birthday" )
    $Bday= $item.DateTimeValue
    if $bday.dateonly <> "" then 
        $user = $addr_Doc.GETFIRSTITEM("FirstName").text & " " & $addr_Doc.GETFIRSTITEM("LastName").text
        ConsoleWrite('person:' & $user & '   $bday.dateonly = ' & $bday.dateonly & @lf & '>Error code: ' & @error & @lf);### Debug Console
    EndIf
    $Addr_Doc = $Addr_view.GetnextDocument($Addr_Doc)
Wend
Do you have access to the COM API description? There might be a collection you can access so you only get items that exist. Something like:
While 1
    If Not isObj($Addr_Doc) then ExitLoop
    $colItems = $addr_doc.Items
    For $oItem In $colItems
        If $oItem.name = "Birthday" Then
            $Bday = $oItem.DateTimeValue
            if $bday.dateonly <> "" then 
                $user = $addr_Doc.GETFIRSTITEM("FirstName").text & " " & $addr_Doc.GETFIRSTITEM("LastName").text
            EndIf
        EndIf
        ExitLoop
    Next
    $Addr_Doc = $Addr_view.GetnextDocument($Addr_Doc)
Wend

That probably won't work verbatim, but something like it might be possible if you have the documentation.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

hey psalty =)

thanks for responding...

i think this is what you're talking about - i see the item field but im trying to figure out how to use this documentation

http://www-12.lotus.com/ldd/doc/tools/c/6.0.2/api60ref.nsf

Edited by gcue

Share this post


Link to post
Share on other sites

Not sure I understand your issue but Errorhandling can be implement by using a standard com error handler.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Not sure I understand your issue but Errorhandling can be implement by using a standard com error handler.

Yeah, I was thinking it was better to fix/avoid the COM error than to handle/ignore it. But there should be a COM error handler in any script that uses COM objects anyway.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

the error handling im trying to accomplish is if the field "birthday" isnt found skip it and go to the next addressbook entry

actually heres a better sample:

so if the addbk entry doesnt have "Title" for instance it crashes the script instead of just setting $Title as blank

maybe now that i think of it.. "error handling" might be the wrong phrase... ??

While 1
    If Not IsObj($Addr_Doc) Then ExitLoop
    $FirstName = $Addr_Doc.GetFirstItem("FirstName" ).Text
    $MiddleName = $Addr_Doc.GetFirstItem("MiddleInitial" ).Text
    $LastName = $Addr_Doc.GetFirstItem("LastName" ).Text
    $Fullname = $Addr_Doc.GetFirstItem("FullName" ).Text
    $Title = $Addr_Doc.GetFirstItem("Title" ).Text
    $Suffix = $Addr_Doc.GetFirstItem("Suffix" ).Text

   $Addr_Doc = $Addr_view.GetnextDocument($Addr_Doc)
wend
Edited by gcue

Share this post


Link to post
Share on other sites

Just put in the ComErrorHandler and test for @error where you want ot test.

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")


While 1
    If Not IsObj($Addr_Doc) Then ExitLoop
    $FirstName = $Addr_Doc.GetFirstItem("FirstName" ).Text
    $MiddleName = $Addr_Doc.GetFirstItem("MiddleInitial" ).Text
    $LastName = $Addr_Doc.GetFirstItem("LastName" ).Text
    $Fullname = $Addr_Doc.GetFirstItem("FullName" ).Text
    $Title = $Addr_Doc.GetFirstItem("Title" ).Text
    $Suffix = $Addr_Doc.GetFirstItem("Suffix" ).Text
   $Addr_Doc = $Addr_view.GetnextDocument($Addr_Doc)
wend

; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

i want to test for every field so do i put it after every line within the while?

thanks for your help!

Edited by gcue

Share this post


Link to post
Share on other sites

i want to test for every field so do i put it after every line within the while?

thanks for your help!

Have you tried? :)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

yep - but i know im doing something very wrong

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $g_eventerror = 0

;Start a session to notes
$Session = ObjCreate("Notes.NotesSession")
$Addr_db = $Session.GetDatabase ("", "c:\names.nsf")
$Addr_view = $Addr_db.GetView("People")
$Addr_Doc = $addr_View.GetFirstDocument
$x=0
;' check in the view

While 1
    If Not IsObj($Addr_Doc) Then ExitLoop
    $FirstName = $Addr_Doc.GetFirstItem("FirstName" ).Text
    $MiddleName = $Addr_Doc.GetFirstItem("MiddleInitial" ).Text
    $LastName = $Addr_Doc.GetFirstItem("LastName" ).Text
    $Fullname = $Addr_Doc.GetFirstItem("FullName" ).Text
    $Title = $Addr_Doc.GetFirstItem("Title" ).Text
    $Suffix = $Addr_Doc.GetFirstItem("Suffix" ).Text

     If $g_eventerror Then MsgBox(48, "Error.", "")

   $Addr_Doc = $Addr_view.GetnextDocument($Addr_Doc)
wend

; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:")
    SetError(1); something to check for when this function returns
    $g_eventerror = 1
    Return
EndFunc   ;==>MyErrFunc

Share this post


Link to post
Share on other sites

Try changing:

If $g_eventerror Then MsgBox(48, "Error.", "")

to

If @error Then MsgBox(48, "Error.", "")

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

just tried that - i keep getting the same error with fields that dont exist in some of the addbk records:

(17) : ==> Object referenced outside a "With" statement.:

$Title = $Addr_Doc.GetFirstItem("Title" ).Text

$Title = $Addr_Doc.GetFirstItem("Title" )^ ERROR

if i comment the fields that arent available in all the addbk entries it works

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

;Start a session to notes
$Session = ObjCreate("Notes.NotesSession")
$Addr_db = $Session.GetDatabase ("", "c:\names.nsf")
$Addr_view = $Addr_db.GetView("People")
$Addr_Doc = $addr_View.GetFirstDocument
$x=0
;' check in the view

While 1
    If Not IsObj($Addr_Doc) Then ExitLoop
    $FirstName = $Addr_Doc.GetFirstItem("FirstName" ).Text
    $MiddleName = $Addr_Doc.GetFirstItem("MiddleInitial" ).Text
    ;$LastName = $Addr_Doc.GetFirstItem("LastName" ).Text
    $Fullname = $Addr_Doc.GetFirstItem("FullName" ).Text
    ;$Title = $Addr_Doc.GetFirstItem("Title" ).Text
    ;$Suffix = $Addr_Doc.GetFirstItem("Suffix" ).Text

     If @error Then MsgBox(48, "Error.", "")

ConsoleWrite($FirstName & "," & $MiddleName & "," & $Fullname & @lf)

   $Addr_Doc = $Addr_view.GetnextDocument($Addr_Doc)
wend

; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:")
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

thanks again for your help/patience

Edited by gcue

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

just tried that - i keep getting the same error with fields that dont exist in some of the addbk records:

if i comment the fields that arent available in all the addbk entries it works

Do you mean the ConsoleWrite() message that is in your error function? Comment it out if you don't want to see it.

Edit: Oops. That's just because it's not an object when it fails. Break it down a bit:

While 1
    If Not IsObj($Addr_Doc) Then ExitLoop
    $oItemField = $Addr_Doc.GetFirstItem("FirstName")
    $FirstName = $oItemField.Text
    $oItemField = $Addr_Doc.GetFirstItem("MiddleInitial")
    $MiddleName = $oItemField.Text
    $oItemField = $Addr_Doc.GetFirstItem("FullName")
    $Fullname = $oItemField.Text

    If @error Then MsgBox(48, "Error.", "")

    ConsoleWrite($FirstName & "," & $MiddleName & "," & $Fullname & @LF)

    $Addr_Doc = $Addr_view.GetnextDocument($Addr_Doc)
WEnd

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

hehe no not that =) (the same error is the one i mention above:

i get an error:

(17) : ==> Object referenced outside a "With" statement.:

$Title = $Addr_Doc.GetFirstItem("Title" ).Text

$Title = $Addr_Doc.GetFirstItem("Title" )^ ERROR

i get that error even if i comment out the consolewrite in the error function.

i think im not explaining myself correctly, for this i apologize

here is what im trying to do:

from a file names.nsf (which is a lotus notes addressbook) i am trying to pull the several fields like firstname, lastname, etc

this works great if these fields are available in each addressbook entry the script goes through. however, if the field is blank for that particular addressbook entry, i get an error. what i would like is for the script to provide with what it can pull without any errors. if it cant find the field im asking for, just leave a blank.

for instance:

addressbook entries

FirstName:Bob

LastName:Smith

Title:Mr.

FirstName:Mary

LastName:Jenkins

Title:

the script crashes on mary jenkins when trying to pull title because its blank in the addressbook. so i guess i dont need an error i just need a blank entry bc it doesnt exist.

hope that makes sense =/

Share this post


Link to post
Share on other sites

See my update above.

I may not be helping though. I haven't been inflicted with Lotus, and just tried to infer the problem from the code and your description.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

oo that looked promising but i got the error after all

(64) : ==> The requested action with this object has failed.:

$Title = $oItemField.Text

$Title = $oItemField.Text^ ERROR

Share this post


Link to post
Share on other sites

oo that looked promising but i got the error after all

(64) : ==> The requested action with this object has failed.:

$Title = $oItemField.Text

$Title = $oItemField.Text^ ERROR

I am not using Notes the last 2 year and have no means to test any of this anymore.

Reading this last post make me wonder what the content of $oItemField is after this line:

$oItemField = $Addr_Doc.GetFirstItem("FirstName")

Try displaying it.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

psalty's suggestion worked!!!

sorry it was my fault i had left the .text on the first field

yipeeeee!!

thank you very very much fellas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0