Bad Data and Bad Behavior
Learn about the specialized exceptions for handling loading errors and enhancing user authorization.
We'll cover the following...
What can go wrong?
It helps to consider what can go wrong when loading a Sample
object, and what–if anything–the user can do about it. Our sample validation rules suggest we may want to raise specialized kinds of ValueError
exceptions to describe data, where the measurements aren’t valid float values or the species name, isn’t one of the known strings.
We can use a class like the following to define the condition of bad data that can’t be processed:
Press + to interact
class InvalidSampleError(ValueError):"""Source data file has invalid data representation"""
This lets us raise an InvalidSampleError
exception for input data that this application can’t process. The intent is to provide a message with the details ...