Sign in to follow this  
Followers 0
VelvetElvis

Handling Windows Errors

5 posts in this topic

Had a separate thread going regarding an issue with ShellExecuteWait(). Didn't get any satisfactory resolution, outside of parsing the event logs, so I thought I'd break it down and present the root problem.

I simply want a way to deal with Windows errors such as what this example causes:

Opt("WinTitleMatchMode", 2) ; Should catch "missingfile.exe" anywhere in the window error message
AdlibRegister("CatchErrorMsg")
ShellExecute("missingfile.exe")
MsgBox(0, "", "Error acknowledged and closed")
Exit
; ***********************************************************
Func CatchErrorMsg()
If WinExists("missingfile.exe") Then
  WinActivate("missingfile.exe")
  WinWaitActive("missingfile.exe")
  MsgBox(0, "", WinGetText("missingfile.exe"))
  Send("{ENTER}")
EndIf
EndFunc

I know I can validate for a missing file. This was just used as a way of generating the type of error I'd like to be able to trap. The AdlibRegister() routine I used doesn't even trigger.

Can someone enlighten me, or provide a chunk of code that would trap this error? Or is this type of error a real bear to deal with? I'm at a loss.

Thanks.

Share this post


Link to post
Share on other sites



Instead of trying to trap for the error, you should try very hard to prevent it from happening in the first place by. As you said, you know you can validate for a missing file, then that's exactly what you should do before trying to run the file. If you have other errors due to something that can be checked before you get the errors, that is the best way of eliminating them.

Give an example of an actual error that you want to trap that you might run into and I'm sure someone will come up with a way of preventing it from happening, or even might have a way of catching it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks for replying.

(Here's my original thread for reference.)

http://autoitscript.com/forum/topic/134623-handling-a-shellexecutewait-error/page__view__findpost__p__938619

In essence, I'm shelling out to run an external .exe. The app I'm calling has a ton of .dll and other dependencies, so rather than search for all the files (the folder for this app has 57 files), I thought I would do well to have a generic error handler that I could use so my app doesn't die, and I could exit somewhat gracefully. A missing file might only be one issue, and the problem is, I don't know what other ones could crop up via this app. I don't need anything pretty at this point - just something that would recognize an unidentified error, and close it so that my app could log an error and exit (it will be running unattended 7 days/week)

So I'm guessing what I'm looking for doesn't exist. :D

Share this post


Link to post
Share on other sites

A simple _FileListToArray in the folder with the files, loop through the array and check for the files to see if they exist using a For...Next loop. It's very simple and relatively fast. If the files aren't there, and your computer is on a network with access to other computers/servers, you could copy the missing files from a central repository to the computer running the script/program.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi BrewManNH;

A missing file or files is only one example of what could go wrong.

I'm trying to find a generic, catch-all error handler for any event that would cause a Windows error dialog to pop up while my script is shelled out. I only need to be able to recognize it, log the fact that an error occurred, and close my app gracefully. If not, my app could be hung for an entire weekend with no one around.

I can deal with the errors I know may occur - it's the ones I don't know that can kill my app.

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