Your programs are eventually going to have errors. Generally, errors fall into two categories: errors in the design of the program logic (bugs), and errors that happen when the code is used incorrectly. The first type of error can be minimized with thoughtful program design, and caught by thorough testing (described in the next section). Errors of the second kind are almost guaranteed to happen. An integer will be passed where a float is expected, a denominator will approach zero, or there won't be enough lines in a data file. In Python, these runtime errors are called exceptions
, to distinguish them from syntax errors that will prevent a program from running. We can easily generate a few examples on the command line. Here's a TypeError
exception, which occurs when something has the wrong type:
sage: sin("one") ----------------------------------------------------------------------- TypeError Traceback (most recent call last) /Users...