Jump to content
Sign in to follow this  
RichE

Error Handling

Recommended Posts

RichE

I've written an app the reads from a list of workstations and connects to each and retrieve its wmi data for inventory purposes, whilst it works like a dream and has saved me countless hours crawling around under desks to get serial numbers, every now and then it encounters a pc that crashes the app.

Now when this pc is 350 odd into a 550 pc list it gets a bit frustrating.

so whats the best way to catch these errors and get the app to continue with the rest of the list.


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites
wraithdu

It depends entirely where it is crashing, and what you mean by a crash. Is it an AutoIt fatal error, like array out of bounds or something, or is it a real Windows crash? If it's from AutoIt, you need better error checking in your script. Since you're using WMI, I would think testing IsObj() is a good place to start.

Share this post


Link to post
Share on other sites
RichE

It depends entirely where it is crashing, and what you mean by a crash. Is it an AutoIt fatal error, like array out of bounds or something, or is it a real Windows crash? If it's from AutoIt, you need better error checking in your script. Since you're using WMI, I would think testing IsObj() is a good place to start.

I test for IsObj() already, I'll get it to crash and post up the error


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites
RichE

Would you believe it.. tested it against the PC that crashed it last time and it worked... Grrrr!.

Posted Image

Edited by RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites
wraithdu

Here:

;output.
                        $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
                        If Not IsObj($objSWbemLocator) Then
                        EndIf

                        $objSWbemServices = $objSWbemLocator.ConnectServer($data[1], "root\cimv2", GUICtrlRead($Domain) & "\" & GUICtrlRead($admin), GUICtrlRead($pass))
                        If Not IsObj($objSWbemServices) Then
                        EndIf

You are not checking your objects. First probably won't fail, but second one certainly could which would cause your first call to ExecQuery to raise a fatal COM error.

You should register an AutoIt COM error handler with ObjEvent() to trap any COM errors and avoid any AutoIt fatal errors.

Edited by wraithdu

Share this post


Link to post
Share on other sites
RichE

Here:

;output.
                        $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
                        If Not IsObj($objSWbemLocator) Then
                        EndIf

                        $objSWbemServices = $objSWbemLocator.ConnectServer($data[1], "root\cimv2", GUICtrlRead($Domain) & "\" & GUICtrlRead($admin), GUICtrlRead($pass))
                        If Not IsObj($objSWbemServices) Then
                        EndIf

You are not checking your objects. First probably won't fail, but second one certainly could which would cause your first call to ExecQuery to raise a fatal COM error.

You should register an AutoIt COM error handler with ObjEvent() to trap any COM errors and avoid any AutoIt fatal errors.

Thanks I'll look into it. :)


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites
RichE

I found a different way of processing the information, I've created a main app that calls a sub app for the info gathering, that way if the sub app crashes, the main app continues, and it also poll multiple workstations at the same time which has a faster return rate, I know this isn't the best way to do it but I couldn't seem the get the objevent() error catcher to work :)

thanks again for the help


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites
wraithdu

Sounds like you found an efficient way to ignore the problem... but to each his own. Ideally you need to find out where your code is broken and fix it.

I can guarantee you it is somewhere I mentioned above where you are not checking those objects. Regarding the error handler, the syntax is cake. Just make sure you assign it to a global variable that doesn't go out of scope and is not destroyed (the help file should really mention that).

Global $comErr = ObjEvent("AutoIt.Error", "MyCOMErrHandler")

Share this post


Link to post
Share on other sites
RichE

Sounds like you found an efficient way to ignore the problem... but to each his own. Ideally you need to find out where your code is broken and fix it.

I can guarantee you it is somewhere I mentioned above where you are not checking those objects. Regarding the error handler, the syntax is cake. Just make sure you assign it to a global variable that doesn't go out of scope and is not destroyed (the help file should really mention that).

Global $comErr = ObjEvent("AutoIt.Error", "MyCOMErrHandler")

Ok Yea, I was being lazy, and I've (with a kick up the bum from you) sorted it properly, whilst we're on, now that I've a more efficient way of gathering data, would there be any way to pass the info back to a compiled .exe that is already running to populate a listview, the only way I could think of was to write the info to a file and then get the other .exe to read it, which would mean getting the process ID's of each session and reading the file then deleting it.

do you have any tips or ideas..?


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites
wraithdu

There are several options, some easier than others depending on your level of experience. You can use the file method you mentioned, or the registry. You can also explore other IPC (inter-process communication) avenues, such as named pipes, mailslots, and the WM_COPYDATA message. Personally, I use WM_COPYDATA, but mailslots seem to be popular as well. There is a mailslot UDF floating around the forum somewhere.

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  

×