As the title states – instead of printing the exception, is it good practice to execute code in the except clause, which solves the error raised in the try clause?
For example, I'm creating a wrapper for Mininet, which creates some network topology. However, if the previous instance of the network topology isn't stopped, the creation fails, and the previous network must be cleaned up before the creation can succeed. This is done by executing the Mininet CLI command sudo mn -c
. See the code below.
class MininetWrapper:
def __init__(self):
try:
self.net = Mininet(topo=<topology>, controller=<controller>)
except:
os.system('sudo mn -c')
self.net = Mininet(topo=<topology>, controller=<controller>)
self.net.start()
If the above is not good practice, please suggest a better method.