AutoHotkey Community

It is currently May 27th, 2012, 12:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: September 29th, 2005, 1:41 pm 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
Hi Chris,

what about errorhandling in AutoHotkey

Code:
OnError, Label  ; Error is stored in A_ErrorMessage or A_ErrorID


or like in Javascript with try {} catch(e) {} ?

Also nice would be a
Code:
DebugMode, On|Off|1|0


If it is Off, all OutputDebug-Commands are skipped.

_________________
Tekl


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2005, 2:14 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I'm not sure what types of errors you had in mind with OnError. Perhaps you could give some examples.

In any case, these sound useful so I'll add them to the list for future consideration. Thanks for continuing to post your ideas.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2005, 8:41 pm 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
Hi,

it was no error in specific. It just to get rid of those messages which a normal user cannot understand. For example I have a script which uses commands which are not present in an old AHK-version on the users computer. Instead of confusing him with a message, that a command could not found the OnMessage-Routine could catch it and tells him what to do: "Before reporting a bug, try updating AutoHotkey. Press Update to automatically download AutoHotkey. If you already have the newest version press send bug-report which will send a log-file to the author" or something like that.

As I include a file with hotstrings in my script it could be that something is wrong with the hotstrings-file so AutoHotkey will stop the script. This could be detected by the OnError-Routine which renames the hotstings-file to let the script work without it.

Just some ideas.

_________________
Tekl


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2005, 3:51 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Due to the way scripts are loaded, both of the above examples for OnError would be difficult to implement. Another problem is that I don't think there's a reliable way to tell the difference between a real syntax error and one for which the installed AHK version is too old.

Even so, I'll give more thought to it in case I've overlooked something.

In the meantime, you could have a starter script check the variable A_AhkVersion and only if it's new enough launch the main script. I realize this is clumsy, but it might be appropriate in some cases.

Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2005, 4:57 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Chris wrote:
In the meantime, you could have a starter script check the variable A_AhkVersion and only if it's new enough launch the main script. I realize this is clumsy, but it might be appropriate in some cases.


Actually, this is the method Mozilla Firefox employs to ensure compliance of extensions.

If it's good enough for Firefox...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2005, 7:58 am 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
Code:
In the meantime, you could have a starter script check the variable A_AhkVersion and only if it's new enough launch the main script. I realize this is clumsy, but it might be appropriate in some cases.


That's what I'm actually doing and even if OnError would exist I won't do it all in one script because the starter-script only exists after an update checking the ahk-version and does some things that the main-script never needs to do. After executing it also deletes itself.

Code:
Due to the way scripts are loaded, both of the above examples for OnError would be difficult to implement. Another problem is that I don't think there's a reliable way to tell the difference between a real syntax error and one for which the installed AHK version is too old.


It was just an example. It would also help to create a custom error-dialog with a message in the preferred language and maybe a button or an edit-control to copy the real error-message into clipboard, so that a user can mail it to the author.

_________________
Tekl


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2005, 1:02 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Quote:
It was just an example. It would also help to create a custom error-dialog with a message in the preferred language and maybe a button or an edit-control to copy the real error-message into clipboard, so that a user can mail it to the author.
Most things (such as Run) have a UseErrorLevel mode now. Please let me know if you discover any remaining sources of errors for which a UseErrorLevel mode would be desirable (other than syntax errors that prevent a script from launching).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2005, 2:22 pm 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
Hi Chris,

there are not many sources left. But for example I had a mistake in a complex script where I forgot a Gui, Destroy in an GuiEscape-Label. I forgot to test the dialog in every case. A user then called the dialog, escaped it and after recalling the dialog he got the error, that a variable cannot be assigned again to another gui-element. The user didn't know what it mean and even didn't know if it was his mistake. As the script is quite complex I think there can be other error-sources and then I want to inform the user, that he has to inform me to get the bug fixed.

In my case it would help to make the error-dialog customizeable:
Code:
#CustomErrorMessage: An error occured while executing the script. Please copy the message below into a mail and mail it to the author ...

Well language-specific would be better (with variables), but I think AHK has to get the custom-message before a error can occur. Maybe a #CustomErrorMessage0407:/#CustomErrorMessage*07 could do it.

I hope you understand what I mean.

_________________
Tekl


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2005, 3:22 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for the details. There is a plan to add a UseErrorLevel mode to Gui (like the one for the Menu command). However, it's not be as good as your #CustomErrorMessage idea for all purposes, so I'm not sure which will wind up getting done.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2005, 7:48 am 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
Thanks!

_________________
Tekl


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group