Closing all windows if an exceptions occurs

Hello,

I was wondering if there was a way to have the script close all windows (similar to what happens at the end of any script) if an exception occurs. I have a bot that is going into a web page to generate reports for a list of store numbers. If one of the reports doesn’t generate, the exception handling catches it but it doesn’t continue generating the reports from the next store number in the list because it cannot log into the webpage if it’s already logged in from the previous steps.

Any help is greatly appreciated.

Here is a simple idea of how I set up the script.

To clarify:

I’ve tried having the bot log out of the website if an exception occurs but it just doesn’t seem to work. It would be ideal if the bot could just close everything if an exception occurs so that the next iteration of store number could start fresh.

Open to any other ideas as well.

Thanks!

Hey Brandon! What if you use Get Window Title actions to get the window titles of the applications that need to close, then use Close Window actions in your exception handling.

No, they don’t.

Use with statement if you want your files to be closed even if an exception occurs.

From the docs:

The with statement is used to wrap the execution of a block with methods defined by a context manager. This allows common try…except…finally usage patterns to be encapsulated for convenient reuse.

From docs:

The with statement allows objects like files to be used in a way that ensures they are always cleaned up promptly and correctly.

with open(“myfile.txt”) as f:
for line in f:
print line,
After the statement is executed, the file f is always closed, even if a problem was encountered while processing the lines. Other objects which provide predefined clean-up actions will indicate this in their documentation.