Jump to content
Simpel

Error handler: err.scriptline -1

Recommended Posts

Simpel

Hi.

I have an error handler that show as err.scriptline always -1 if compiled. Example:

Global $oMyError = ObjEvent("AutoIt.Error", "_ErrorHandler")
_Example()
Exit

Func _Example()
    Const $bAdoStateOpen = 1
    Local $oAdoConnection = ObjCreate("ADODB.Connection")
    $oAdoConnection.properties("Prompt") = 2
    Local $sQuery = "DRIVER={Oracle in Orahome11_32Bit};SERVER=NDRVPN;DBQ=VPNM.;UID=preview;PWD=btb_cwfiywc;"
    If $oAdoConnection.state = $bAdoStateOpen Then $oAdoConnection.close
    $oAdoConnection.connectionstring = $sQuery
    $oAdoConnection.open ; ################################# This causes the error ################################
    If $oAdoConnection.state <> $bAdoStateOpen Then
        Return SetError(1)
    EndIf
EndFunc

Func _ErrorHandler()
    Local $HexNumber = Hex($oMyError.number,8)
    MsgBox(0,"Fehler","An error occured:" & @CRLF & _
        "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
        "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
        "err.number is: "         & @TAB & $HexNumber              & @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)
    Return SetError(1)
EndFunc

If I run this script from SciTE it shows err.scriptline: 12:

Error_Message_uncompiled.PNG.3d20cb3adba8564043299f0aa47298d6.PNG

But if I compile err.scriptline is: -1:

Error_Message_compiled.PNG.ac318ac457e07626959ca6267d3ce53b.PNG

How can I fix this?

Regards, Conrad


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

sorry, cannot read German to read that error. from your error number it looks like a Logon Failure

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
mLipok
Posted (edited)

@Simpel this is very similar question, and answer like this following:

 

EDIT:
err.scriptline -1 is because you are using compiled script, which will not return @ScriptLineNumber

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
Simpel

Hi.

So @mLipok, by the way you probably solved the error behind that question. But that was not intended. That’s why I did post the german messages - only wanted to show the behavior with scriptline.

I was looking for an error handler telling me the scriptline even if compiled. Of course I have to deal with error handling in the code at every point there could something happen. But there will always be parts of code I do forget to check. So I don’t want to crash the script but catch the error messages including scriptline to solve that error later (I ask my users to make a screenshot). But if that kind of error handler can’t handle the scriptlines I had to disable this and better let crash my tool but with an message including a scriptline. Or is there another possibility?

Conrad


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
mLipok
27 minutes ago, Simpel said:

I was looking for an error handler telling me the scriptline even if compiled. Of course I have to deal with error handling in the code at every point there could something happen.

This following conceptual snippet:

#Au3Stripper_Parameters=/MO /RSLN

_Example()
Func _Example()
    _SomeFunction()
    If @error Then MsgBox($MB_ICONERROR, 'SomeFunction', '@error = ' & @error & @CRLF & '@extended = ' & @extende & @CRLF & '@ScriptLineNumber = ' & @ScriptLineNumber)
EndFunc

Func _SomeFunction()
    Return SetError(1)
EndFunc

is soultion to your problem - of course in outline, because it's just a sketch.

I'm using such kind of @error handling all the last 3..5 years, with quite good success. For this reason I rewrite few UDF (ADO, POP, XML, and few of my own) - to have better error handling + parameters validation.

 

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
Simpel

That kind of handler I use to catch errors in that part of scripts I write myself. But there are two things I can’t barely deal with. First are UDFs from others which I should understand but shouldn’t rewrite at all, I think. Probably I have to.

But more important and that’s the problem here are errors with objects. Errors with objects will definitely crash the script if not catch with an error handler function like above or am I wrong? Is there a possibility catching them and showing the err.scriptline? The crashing messages on object errors (if not having an error handler) are showing the correct error scriptline. So how can I do that by myself and not exiting/crashing the script?

Conrad

P.S. Anyway, on monday I will expand my “normal” error handling with /rsln for errors not dealing with object errors.


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
mLipok
Posted (edited)
1 hour ago, Simpel said:

But more important and that’s the problem here are errors with objects.

Check my ADO and XML UDF and focus on how I handle COM errors.

If COM errors is fired then I set and return specyfic @error and @extended

IMHO each other UDF using ActiveX Object  should report COM issues to @error and @extended in a similar way.

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

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

×