Sign in to follow this  
Followers 0
michaelslamet

When compiled, how to know which line is error

40 posts in this topic

When our compiled script error, how to know which line that caused that error?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

That depends on the type of error. If the error causes the interpreter to crash, I don't know a solution. If it is an exception you expect to occur, you could code for it using @ScriptLineNumber. You should first test everything thoroughly before compiling to avoid errors anyway.

Edit

Strike out

Edited by czardas

Share this post


Link to post
Share on other sites

Add error checking code to your script and test, test, test to find as much errors as possible before you use the script in production.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@czardas: thanks @ScriptLineNumber macro, I will look at it.

@water and czardas: yes, I will :) But nobody know's what will happen in the future, let say when the PC upgrade the OS or upgrade the service pack or anything else :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I just realised that @ScriptLineNumber doesn't work with compiled scripts. I'll test it and see.

Edit

I was right, it's no use - sorry for the misinformation.

Edited by czardas

Share this post


Link to post
Share on other sites

The subject @ScriptLineNumber in compiled scripts has been discussed many times. The forums search feature is your friend ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No problem, czardas, thanks for trying to help! :thumbsup:

So there is no way?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

So you have to hard code the line numbers if you want to know where an error occurs when compiled using something like this.

Global $sLine1 = "Line 1"
SetError (1) ; Error induced for the demo
If @error Then
    MsgBox(0, "", "Error occured at line 2")
    Exit ; or do something else
EndIf
Edited by czardas

Share this post


Link to post
Share on other sites

Unfortuntely for my scenario at this moment, it cant be done that way, because:

1. the script is 1000++ lines.

2. the error occure sometime, sometime not.

It only throw an error when run as compiled and never when run from SciTe

Share this post


Link to post
Share on other sites

This brings to mind the question, of why you would want to know, if the source script is no longer available to you?

Surely, if the uncompiled script is available, you would always want to test with that, even doing compiles as needed during troubleshooting.

Else, you should always code you programs to return errors at diligent/smart sections. One should never make presumptions when coding or rely on something not changing, so you should cater for most possibilities.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@TheSaint: I have the source script with me :) It only throw an error when run as compiled and never when run from SciTe

Thanks! :)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Missed your last post #9.

One way, that I sometimes use, is to have certain values and returns, saved to a log file, that you can check if need be ... which can even be a ini file if desired. This method is especially useful where dialogs or SciTE is not helpful, etc.

Edited by TheSaint
1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Let's imagine the scenario that you used a macro such as @ScriptLineNumber in your code. When not compiled the value for @ScriptLineNumber will be different. So when compiled the script won't work as expected. The only way to fix such an error is to rewrite the code using methods that will work when you compile the script.

Share this post


Link to post
Share on other sites

Sometimes, you just implement a manual switch in an ini file, to get the program to do error logging, which if it doesn't find, it doesn't do normally.

I've even on occasion, implemented Screenshots, at key moments, to help detect things the eye misses ... especially when working with third party programs.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

michaelslamet,

water suggested you search the forum - let me save you the trouble as adding the text below is a single keypress. ;)

When compiling your script, run Obfuscator using the /STRIPONLY parameter. That way the compiler uses an au3 file which has the include files included, but all unused functions, variables, comments and blank lines removed. It is saved in the same folder as the source and named YourScriptName_Obfuscated.au3. You need to add these directives to the top of your script:

#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
Then when the error occurs, it is easy to see which line gave the fault as it is this Obfuscated file which has been compiled - just scroll to the indicated location. The only problem we know of is that using the line continuation operator screws up the count, but apart from that it works fine. :)

Of course, you need the full SciTE4AutoIt3 package, which you can download from here if you do not already use it. ;)

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

add another 1000+ lines to your script:  (I would use excel to do that)

trace('1')

..

trace('2')

...

etc.....

Func trace($x)

$tracefile = fileopen(c:mytracefile.txt',1)

FileWriteline($tracefile,$x)

fileclose($tracefile)

EndFunc

 

enjoy,

Share this post


Link to post
Share on other sites

Or use function _FileWriteLog. It automatically adds date and time to the log entries.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Write a small script that reads each line and replaces @scriptlinenumber with the actual line number.

Won't work with the @scriptlinenumber default value for a parameter trick.

1 person likes this

Share this post


Link to post
Share on other sites

@water and czardas: yes, I will :) But nobody know's what will happen in the future, let say when the PC upgrade the OS or upgrade the service pack or anything else :)

That is why you usually test a script in different environments (operating system, versions of other applications the scripts automates (Office, Broser ...) etc.).

Then you add this information to the Readme file so the user knows what to expect from your script. When a new OS is released and the script crashes then the user wouldn't be surprised.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It only throw an error when run as compiled and never when run from SciTe

Can you please tell us which error messages you receive? Do they change or is it always the same?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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