Error Handling#

Exception Classes#

The dftt_timecode library defines custom exception classes for different error conditions.

DFTTError#

class DFTTError[source]#

Bases: Exception

Base exception class for all DFTT Timecode library errors.

All custom exceptions in this library inherit from this base class.

Base exception class for all dftt_timecode errors.

DFTTTimecodeValueError#

class DFTTTimecodeValueError[source]#

Bases: DFTTError

Raised when a timecode value is invalid or out of acceptable range.

Examples include:
  • Frame number exceeding the frame rate limit

  • Invalid drop-frame timecode values

  • Illegal timecode values for the given parameters

Raised when an invalid timecode value is provided.

DFTTTimecodeInitializationError#

class DFTTTimecodeInitializationError[source]#

Bases: DFTTError

Raised when timecode initialization fails due to incompatible parameters.

Examples include:
  • Drop-frame status mismatch with timecode format

  • Incompatible timecode value and type combinations

Raised when timecode initialization fails due to incompatible parameters.

DFTTTimecodeTypeError#

class DFTTTimecodeTypeError[source]#

Bases: DFTTError

Raised when a timecode type is invalid or incompatible.

Examples include:
  • Unknown timecode format type

  • Type mismatch between expected and actual timecode format

  • Invalid data type for timecode operations

Raised when an invalid timecode type is specified or type mismatch occurs.

DFTTTimecodeOperatorError#

class DFTTTimecodeOperatorError[source]#

Bases: DFTTError

Raised when an arithmetic or comparison operation on timecode objects fails.

Examples include:
  • Operations between timecodes with different frame rates

  • Undefined operations (e.g., dividing number by timecode)

  • Invalid operand types for timecode arithmetic

Raised when an arithmetic or comparison operation on timecode objects fails.

DFTTTimeRangeMethodError#

class DFTTTimeRangeMethodError[source]#

Bases: DFTTError

Raised when a timerange method is called with invalid parameters or conditions.

Examples include:
  • Attempting to intersect/union timeranges with different directions

  • Invalid offset or extend values

  • Operations on non-overlapping, non-adjacent timeranges

Raised when a timerange method is called with invalid parameters or conditions.

DFTTTimeRangeValueError#

class DFTTTimeRangeValueError[source]#

Bases: DFTTError

Raised when a timerange value is invalid or out of acceptable range.

Examples include:
  • Zero-length timerange

  • Duration exceeding 24 hours in strict mode

  • Invalid timerange separation parameters

Raised when a timerange value is invalid or out of acceptable range.

DFTTTimeRangeTypeError#

class DFTTTimeRangeTypeError[source]#

Bases: DFTTError

Raised when a timerange type or operand type is invalid.

Examples include:
  • Invalid item type for contains check

  • Attempting to operate on non-timerange objects

  • Type mismatches in timerange operations

Raised when a timerange type or operand type is invalid.

DFTTTimeRangeFPSError#

class DFTTTimeRangeFPSError[source]#

Bases: DFTTError

Raised when timerange operations fail due to frame rate mismatches.

Examples include:
  • FPS mismatch between start and end timecodes

  • Operations between timeranges with different frame rates

Raised when timerange operations fail due to frame rate mismatches.

Error Examples#

Invalid Timecode Value#

from dftt_timecode import DfttTimecode
from dftt_timecode.error import DFTTTimecodeValueError

try:
    tc = DfttTimecode('99:99:99:99', 'smpte', fps=24)
except DFTTTimecodeValueError as e:
    print(f"Invalid timecode: {e}")

Timecode Initialization Error#

from dftt_timecode import DfttTimecode
from dftt_timecode.error import DFTTTimecodeInitializationError

try:
    # Drop-frame status mismatch with timecode format
    tc = DfttTimecode('01:00:00:00', 'smpte', fps=29.97, drop_frame=False)
except DFTTTimecodeInitializationError as e:
    print(f"Initialization error: {e}")

Type Error#

from dftt_timecode import DfttTimecode
from dftt_timecode.error import DFTTTimecodeTypeError

try:
    tc = DfttTimecode('invalid_format', 'unknown_type', fps=24)
except DFTTTimecodeTypeError as e:
    print(f"Type error: {e}")

Operator Error#

from dftt_timecode import DfttTimecode
from dftt_timecode.error import DFTTTimecodeOperatorError

try:
    tc1 = DfttTimecode('01:00:00:00', 'auto', fps=24)
    tc2 = DfttTimecode('01:00:00:00', 'auto', fps=30)
    # Cannot add timecodes with different frame rates
    result = tc1 + tc2
except DFTTTimecodeOperatorError as e:
    print(f"Operator error: {e}")