What are some things one could try to exception handle for? During one of my last interviews I was asked to do error handling and exception handling after solving a problem on the whiteboard. for example one could use try:/except: for -input length, input type (number/string), no input....? my question is, what’s a smart way of doing this in an interview?
Also good to clarify what is intended for the various error states. For example somethings may just need early returns. Some may just return a default response. Others may need to throw an exception.
Post code
You can ask your interviewers to clarify what they're looking for, but my guess is they want you to check for edge cases, so your code won't break under most if not all circumstances. Nulls and type checking, etc. Throwing an exception is one of the worst and laziest ways to handle errors in production code.
I can check for null type input simply by something like “if not nums: return”. But if throwing exception is lazy then how do I better do input type checking such as is string or number. :)
Python has built-in input and output validation in the function declaration.
Check out how to use "raise" in Python.