13,420
edits
Changes
→PART 1 - Handling Errors
::#Issue the following to create an exception error:<source lang="python">
print('5' + 10)
</source><br><br>You should get an exception error similar to the following:<source lang="python">
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: Can't convert 'int' object to str implicitly
</source><br><br>'''Question:''' According to the exception error message, what do you think caused the error?<br><br>
::#Firstly, what to look for here is Click on the exception name following link '[https://docs.python.org/3/library/exceptions.html#TypeError TypeError.]' The Type to determine what a TypeError exception error means .<br><br>You should have learned that the TypeError exception error indicates a mismatch of a type(i.e. string, int, float, list, etc). If Python doesn't know how to handle it, should it perhaps we could change the number into a string or change the string into a number?.
::#If we want to write this program safely, we can catch this error while it's happening. This is done with a specific block of code called a [https://docs.python.org/3/tutorial/errors.html#handling-exceptions try clause] where you place code inbetween the '''try:''' and ''''except:'''. If no error occurs in the code the except portion will be skipped.
::#No Exception:<source lang="python">