Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Try Except stopping program as opposed to skipping over errror

I am running a sequence of scripts that are independent of each other. Meaning if one of them fails I want the rest to continue on and just be notified of the one that failed(I can implement the notification later). For now I am just trying to figure out why the program is not continuing on.

I am trying doing a test in which I have the sequence. However Script 2 in this case has an error as there is not a file its trying to read in. I am getting

FileNotFoundError: [Errno 2] No such file or directory:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And the program is stopping.

def errorFunction(function, name):
    print('Running Script: ' + name)
    try:
        function
    except FileNotFoundError:
        print('FileNotFound Error. Script Name ' + name)
    except:
        print('Error. Script Name ' + name)
        pass

errorFunction(Script1(), 'Script1')
errorFunction(Script2(), 'Script2')
errorFunction(Script3(), 'Script3')

>Solution :

errorFunction(Script1(), 'Script1')

This is your problem. Since there are parentheses on the end of Script1(), you are actually calling that function here, before errorFunction() even executes.

Take off the parentheses here, like so:

errorFunction(Script1, 'Script1')

And then add parentheses here, like so:

try:
    function()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading