Exceptions#
The phylozoo.utils.exceptions module provides a custom exception hierarchy for clear, specific error and warning messages.
All exceptions and functions on this page can be imported from the exceptions module:
from phylozoo.utils.exceptions import (
PhyloZooError,
PhyloZooValueError,
PhyloZooNetworkError,
PhyloZooParseError,
PhyloZooWarning,
warn_on_keyword,
warn_on_none_value,
)
Errors#
Errors are raised when something goes wrong in PhyloZoo.
Base Error Class#
PhyloZooError is the base exception for all PhyloZoo errors.
All custom exceptions inherit from this class. Catch it to handle any PhyloZoo-specific error.
try:
network = DirectedPhyNetwork.load("network.enewick")
except PhyloZooError as e:
print(f"PhyloZoo error: {e}")
General-Purpose Errors#
General-purpose errors inherit from both
PhyloZooError and the corresponding Python built-in,
so code that catches, e.g., ValueError or TypeError still works:
PhyloZooValueError— also inherits fromValueErrorPhyloZooTypeError— also inherits fromTypeErrorPhyloZooRuntimeError— also inherits fromRuntimeErrorPhyloZooNotImplementedError— also inherits fromNotImplementedErrorPhyloZooImportError— also inherits fromImportErrorPhyloZooAttributeError— also inherits fromAttributeError
Domain-specific Errors#
Each domain has a base exception; subclasses provide finer-grained handling. See the Exceptions API for all subclasses.
PhyloZooNetworkError— network structure, degree, and attribute errorsPhyloZooIOError— I/O, parse, and format errorsPhyloZooAlgorithmError— algorithm-related errorsPhyloZooVisualizationError— layout, backend, and state errorsPhyloZooGeneratorError— network generator structure and degree errors
Warnings#
Warnings are raised when the user does something that is not strictly wrong, but might cause unexpected behavior or issues.
Base Warning Class#
PhyloZooWarning is the base exception for all PhyloZoo warnings.
All custom warnings inherit from this class. Catch it to handle any PhyloZoo-specific warning.
try:
network = DirectedPhyNetwork.load("network.enewick")
except PhyloZooWarning as e:
print(f"PhyloZoo warning: {e}")
Specific Warnings#
PhyloZooIdentifierWarning— warn if a value is a Python keyword (e.g. used as an identifier)PhyloZooEmptyNetworkWarning— warn if a network is emptyPhyloZooSingleNodeNetworkWarning— warn if a network has only one node
Warning Utilities#
The exceptions module provides helpers that emit PhyloZoo warnings:
warn_on_keyword()— warn if a value is a Python keyword (e.g. used as an identifier)warn_on_none_value()— warn if a value isNone(Python keyword)
from phylozoo.utils.exceptions import warn_on_keyword, warn_on_none_value
warn_on_keyword("for", "Identifier")
warn_on_none_value(None, "Attribute 'weight'")
See Also#
Exceptions API — full list of exception and warning classes.
I/O — I/O operations and parse/format errors.
Validation — network validation.