2

I'm writing a small production level Flask application that runs on IIS. I've wrapped all of my functions inside try catch blocks and it looks like this.

try:
     #Do Something  
except Exception,e:
     logger.error('Exception in Function X of type : %s ,for Image %s : %s'%(str(type(e)),path,str(e.args)))

I just need to log the problem in most of the cases and use python's builtin logging module to achieve this. I even log the type of the exception sometimes.

Now the thing I'm really concerned about is that although in my specific case, I don't have to handle or recover from any exception and even If I handle specific exceptions with a stack of different except cases, I'll just be logging the error in each block. So,

Is it still necessary for me to catch specific exceptions instead of the generic Exception?

1 Answer 1

2

If the goal is to log all exceptions, then no, you don't have to catch specific ones.

As you noted, there'd be no point as you'd only repeat the same piece of logging.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.