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:

Domain-specific Errors#

Each domain has a base exception; subclasses provide finer-grained handling. See the Exceptions API for all subclasses.

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#

Warning Utilities#

The exceptions module provides helpers that emit PhyloZoo warnings:

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.