From the course: Python Essential Training

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Solution: Bad arguments

Solution: Bad arguments - Python Tutorial

From the course: Python Essential Training

Solution: Bad arguments

Custom annotations work really well with exception handling. It's one of my favorite Python tricks for writing clean enterprise code. For this challenge, you needed to write a new custom exception called non-int argument exception. And this is probably the easiest part. You literally don't need to do anything besides define the class, make it extend exception, and then you can just write pass under that. We just need it defined. Then you want to fill in the rest of this wrapper function under here. As you can see, the function sum down here takes in three arguments, but I opted to make the wrapper handle any number of arguments just by iterating through the args tuple here. I check each one, make sure it's an integer. If it's not an integer, I raise my non argument exception. Finally, I make sure to return the function that was passed in with its original arguments. So remember, if you don't return this, then that will mean that SUM isn't going to return anything, and then the caller…

Contents