Thanks. yeah i didn't mean to go on like that, and i was actually cut short because of work, but to summarize it like someone much smarter than i, implementation of that capability would be very non-trivial.
Wouldnt this code reset the @error macro everytime it was brought around so it would never be the right one?
If I am not mistaken... the @error macro is reset with each new function call. I dont know if that includes the While...WEnd as it isnt a function.
Just my thoughts,
JS
yes, that's kind of what i was trying to say about it not saving any time to use a try/catch if it magically became available, because you'd have to add atleast 2 lines of code for every line of your code that could set the @error.
Func MyFunc()
SomeFuncA()
if @error <> 0 then
msgbox(1,"Error", "Some error")
endif
SomeFuncB()
if @error <> 0 then
msgbox(1,"Error", "Some error")
endif
SomeFuncC()
if @error <> 0 then
msgbox(1,"Error", "Some error")
endif
SomeFuncD()
if @error <> 0 then
msgbox(1,"Error", "Some error")
endif
End Func
where it is hard to see what the code is doing for all the debug code, with:
Func MyFunc()
Try
SomeFuncA()
SomeFuncB()
SomeFuncC()
SomeFuncD()
Catch @error
msgbox(1,"Error", "Some error")
Finally
CleanUpFunc()
End Try
End Func
Which is easier to read.
Behind the scenes, AutoIt would have to monitor the @error returned by each function and jump to the Catch line if it is not zero. Of course there would be no way to know which function caused the error, unless unique error codes are used for each function. On a related note, the addition of an @ErrorMsg macro generated by a function would be good to get around this in that the message could contain more explicit details, including the function name. Similar to err.number and err.description in VB.
Another problem, as identified by cameronsdad is unhandled exceptions. I don't think that there is any way for the code to catch these. My original post was generated because of some COM object code that I was working on, which could generate errors all over the place if the control does not act correctly. There was alot of complicated code, with very little error handling.
Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.
Behind the scenes, AutoIt would have to monitor the @error returned by each function and jump to the Catch line if it is not zero. Of course there would be no way to know which function caused the error, unless unique error codes are used for each function. On a related note, the addition of an @ErrorMsg macro generated by a function would be good to get around this in that the message could contain more explicit details, including the function name. Similar to err.number and err.description in VB.
Another problem, as identified by cameronsdad is unhandled exceptions. I don't think that there is any way for the code to catch these. My original post was generated because of some COM object code that I was working on, which could generate errors all over the place if the control does not act correctly. There was alot of complicated code, with very little error handling.
the thing is, you're not going to have per line error trapping without per line error handling. right now there is the ability to handle errors with a single line usually, where try/catch by it's nature implies atleast 2 addition lines of error trapping, per possible exception thrown. as far as @errormsg macro, we have @error, which can be set to any integer by any function. most of the built in functions that could fail for a variety of reasons have different possible error returns to indicate what exactly the problem is, and any function you create you could throw in your own error with seterror() or even elaborate on that more with setextended(). in any event, if you call 3 functions, and there are 3 different possibilities for errors, you will have to have code to handle 3 different errors. I'm now saying the same things over and over, so i'll try to leave it at that...
Wouldnt this code reset the @error macro everytime it was brought around so it would never be the right one?
If I am not mistaken... the @error macro is reset with each new function call. I dont know if that includes the While...WEnd as it isnt a function.
Just my thoughts,
JS
Yep, you're right based on a quick test. It seemed logical at the time. From the helpfile:
Remarks
When entering a function @error is set to 0. Unless SetError() is called, then @error will remain 0 after the function has ended. This means that in order for @error to be set after a function, it must be explicitly set. This also means you may need to backup the status of @error in a variable if you are testing it in a While-WEnd loop.
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
Here is my goofy workaround for a try catch type block:
And yes I know this thread is ancient...but it is the first google search result for me for autoit try catch so I though others searching might find it useful.
Recommended Posts
John
Nice rant cameronsdad
Makes the point quiet well...
Link to comment
Share on other sites
seandisanti
Link to comment
Share on other sites
JSThePatriot
If I am not mistaken... the @error macro is reset with each new function call. I dont know if that includes the While...WEnd as it isnt a function.
Just my thoughts,
JS
AutoIt Links
File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.
ComputerGetInfo UDF's Updated! 11-23-2006
External Links
Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
Link to comment
Share on other sites
seandisanti
Link to comment
Share on other sites
Stumpii
The idea is to replace:
where it is hard to see what the code is doing for all the debug code, with:
Which is easier to read.
Behind the scenes, AutoIt would have to monitor the @error returned by each function and jump to the Catch line if it is not zero. Of course there would be no way to know which function caused the error, unless unique error codes are used for each function. On a related note, the addition of an @ErrorMsg macro generated by a function would be good to get around this in that the message could contain more explicit details, including the function name. Similar to err.number and err.description in VB.
Another problem, as identified by cameronsdad is unhandled exceptions. I don't think that there is any way for the code to catch these. My original post was generated because of some COM object code that I was working on, which could generate errors all over the place if the control does not act correctly. There was alot of complicated code, with very little error handling.
Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.
Link to comment
Share on other sites
seandisanti
Link to comment
Share on other sites
DaleHohm
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
JSThePatriot
Yea it does still seem logical, but like your quote showed... it isnt.
I am glad you looked it up. I forgot to.
JS
AutoIt Links
File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.
ComputerGetInfo UDF's Updated! 11-23-2006
External Links
Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
Link to comment
Share on other sites
garbb
Here is my goofy workaround for a try catch type block:
And yes I know this thread is ancient...but it is the first google search result for me for autoit try catch so I though others searching might find it useful.
Output:
I am sure someone could improve upon this.
Edited by garbbLink to comment
Share on other sites
Andreik
You are just... 17 years later.
When the words fail... music speaks.
Link to comment
Share on other sites
Nine
And your solution is truly not so good, to say the least...
“They did not know it was impossible, so they did it” ― Mark Twain
Block all input without UAC
Save/Retrieve Images to/from Text
Monitor Management (VCP commands)
Tool to search in text (au3) files
Date Range Picker
Virtual Desktop Manager
Sudoku Game 2020
Overlapped Named Pipe IPC
HotString 2.0 - Hot keys with string
x64 Bitwise Operations
Multi-keyboards HotKeySet
Recursive Array Display
Fast and simple WCD IPC
Multiple Folders Selector
Printer Manager
GIF Animation (cached)
Screen Scraping
Multi-Threading Made Easy
Link to comment
Share on other sites