Appendix A — Stop & Think Answers — Chapter 6
Tip 6.1: When Python tries to evaluate the name gene
and doesn’t find it in any scope, it raises a NameError
, which matches the exception type specified in the except clause. This causes a message with the error details to be printed to the console.
Tip 6.2: FileNotFoundError
Tip 6.3: We could check if the expression value is “na” before trying to convert it, or use a try/except block to catch the ValueError and set a default value (like None
, 1
, 0
, or NaN
).
Tip 6.4: When analyzing sequencing datasets, one error might trigger others in a cascade. For example, a file reading error might lead to missing data, which then causes calculation errors. This chain makes it harder to find the root cause of the error.
Tip 6.5: Specific exceptions might include: FileNotFoundError
, PermissionError
, IsADirectoryError
. All of these could be caught by OSError
, which is the parent class for file-related errors.
Tip 6.6: The finally
clause is useful when working with resources that need to be released regardless of success or failure, such as closing file handles or database connections.
Tip 6.7: Possible custom exceptions: InvalidSequenceError
, AlignmentFailedError
, LowCoverageError
, DifferentialExpressionError
, etc.