Jump to content

Handle COM error ?


Bot
 Share

Recommended Posts

local $oHTML = ObjCreate("HTMLFILE")
$oHTML.Open()
$oHTML.Write($sHTML)
return $oHTML.body.innerText

This COM will convert the $sHTML from HTML code to pure TXT. If the input is HTML then it will work, but if not then it will go wrong :

==> Variable must be of type "Object".: 
return $oHTML.body.innerText 
return $oHTML.body^ ERROR

So how can I determine whether the COM is error or not ?

Link to comment
Share on other sites

See ObjEvent

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

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

$oHTML = ObjCreate("HTMLFILE")
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Func _Html2Text($sHTML)
    $oHTML.Open()
    $oHTML.Write($sHTML)
    return $oHTML.body.innerText
EndFunc

Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _
         "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
         "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
         "err.number is: " & @TAB & hex($oMyError.number,8)  & @CRLF & _
         "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror   & @CRLF & _
         "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
         "err.source is: " & @TAB & $oMyError.source & @CRLF & _
         "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
         "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
    )
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    SetError($err)
Endfunc

Msgbox (0,@error,"")
Msgbox (4096,_Html2Text("<a></a>"),"")

I tried this but the @error is always = 0 even when the error message box is appear or not. Can you fix this for me please ?

Link to comment
Share on other sites

You're trying to display the error before it happens... just change where you placed the MsgBox

$oHTML = ObjCreate("HTMLFILE")

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

Msgbox (4096,_Html2Text("<a></a>"),"")

Msgbox (0,@error,"")

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

$oHTML = ObjCreate("HTMLFILE")
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Msgbox (0,@error,"")
Msgbox (4096,_Html2Text("<a></a>"),"")

Func _Html2Text($sHTML)
    $oHTML.Open()
    $oHTML.Write($sHTML)
    return $oHTML.body.innerText
EndFunc

Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _
         "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
         "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
         "err.number is: " & @TAB & hex($oMyError.number,8)  & @CRLF & _
         "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror   & @CRLF & _
         "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
         "err.source is: " & @TAB & $oMyError.source & @CRLF & _
         "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
         "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
    )
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    SetError($err)
Endfunc

I have changed to it but the @error is still = 0. :) Can you give me another chance please ?

Link to comment
Share on other sites

It wasn't for me... it was 169 (although you put @error in the title bar of the messagebox instead of in the display area, so perhaps that confused you?)

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _
         "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
         "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
         "err.number is: " & @TAB & hex($oMyError.number,8)  & @CRLF & _
         "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror   & @CRLF & _
         "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
         "err.source is: " & @TAB & $oMyError.source & @CRLF & _
         "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
         "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
    )
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    SetError($err)
Endfunc

Msgbox (0,"",@error)

I think I must place the error message box after the function, then it will be 169 like you :P. Thank you very much for your help. :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...