错误处理#
异常类#
dftt_timecode 库为不同的错误情况定义了自定义异常类。
DFTTError#
- class DFTTError[源代码]#
- 基类: - Exception- Base exception class for all DFTT Timecode library errors. - All custom exceptions in this library inherit from this base class. 
所有 dftt_timecode 错误的基础异常类。
DFTTTimecodeValueError#
- class DFTTTimecodeValueError[源代码]#
- 基类: - 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 
 
 
当提供无效的时码值时抛出。
DFTTTimecodeInitializationError#
- class DFTTTimecodeInitializationError[源代码]#
- 基类: - 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[源代码]#
- 基类: - 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[源代码]#
- 基类: - 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[源代码]#
- 基类: - 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[源代码]#
- 基类: - 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[源代码]#
- 基类: - 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[源代码]#
- 基类: - 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}")