MarkItDownException class.
Exception Hierarchy
Exception Classes
MarkItDownException
MarkItDownException
MissingDependencyException
MissingDependencyException
MissingDependencyException
Raised when a converter recognizes a file format but the required optional dependencies are not installed.Inheritance
Inherits fromMarkItDownException.When Raised
This exception is thrown when:- A converter’s
convert()method is called - The converter recognizes the file format
- Required optional dependencies for that format are not installed
This is not necessarily a fatal error. The converter will be skipped, and MarkItDown will try other converters. An error only bubbles up if no suitable converter is found.
Error Message Format
The error message clearly indicates which dependency is missing and provides installation instructions:Example
UnsupportedFormatException
UnsupportedFormatException
UnsupportedFormatException
Raised when no suitable converter was found for the given file.Inheritance
Inherits fromMarkItDownException.When Raised
This exception is thrown when:- MarkItDown has tried all available converters
- None of the converters support the file format
- The file extension or content type is not recognized
Example
FileConversionException
FileConversionException
FileConversionException
Raised when a suitable converter was found, but the conversion process fails.Inheritance
Inherits fromMarkItDownException.Constructor Parameters
Attributes
When Raised
This exception is thrown when:- A suitable converter was found for the file
- The conversion process started but failed
- The file may be corrupted or have unexpected content
Auto-Generated Error Messages
If no message is provided:- Without attempts:
"File conversion failed." - With attempts: Detailed message listing each failed attempt with converter name and error details
Example
Complete Exception Handling Example
Here’s a comprehensive example showing how to handle all MarkItDown exceptions:Best Practices
Specific Exception Handling
Catch specific exceptions before the base
MarkItDownException to handle different error scenarios appropriately.Check Attempts
When handling
FileConversionException, check the attempts attribute for detailed diagnostic information.Graceful Degradation
Handle
MissingDependencyException gracefully by providing clear installation instructions to users.User Feedback
Use exception messages to provide helpful feedback to users about what went wrong and how to fix it.