How not to stop the execution of other function in python in case of Exception/Error
<p>I have a script in python which works as shown below. Each function performs a completely different task and not related to each other. My problem is if <strong>function2()</strong> is having an issue during the execution process then <strong>function3()</strong>, <strong>function4()</strong>, <strong>function5()</strong> will not execute. I know you will say to handle this by catching the exception (try..except) but then i have to catch every exception which is not i am looking for. In a nutshell how do i code where my other functions are not impacted if any of the function is having issue. Ideally it should exclude that problematic function and let the other function to execute.</p>

<pre><code>def function1():
    some code

def function2():
    some code

def function3():
    some code

def function4():
    some code

def function5():
    some code

if __name__ == '__main__':
    function1()
    function2()
    function3()
    function4()
    function5()
</code></pre>

<p>You can use exception and catch all sort of exceptions like this</p>

<pre><code>if __name__ == '__main__':
    try:
        function1()
    except:
        pass
    try:
        function2()
    except:
        pass    
    try:
        function3()
    except:
        pass    
    try:
        function4()
    except:
        pass
</code></pre>

<p>for large number of functions you can use</p>

<pre><code>func_dict = {
 func1 : {
     param1 : val
     param2 : val
   },
 func1 : {
     param1 : val
     param2 : val
   }
}
</code></pre>

<p>thus you can iterate over the keys of the dictionary for the function and iterate on the parameters </p>

python python-2.7