Skip to main content
MarkItDown defines a hierarchy of exception classes to handle various error scenarios during file conversion. All MarkItDown-specific exceptions inherit from the base MarkItDownException class.

Exception Hierarchy

Exception Classes

MarkItDownException

Base exception class for all MarkItDown-specific exceptions.

Inheritance

Inherits from Python’s built-in Exception class.

Usage

This is the base class for all MarkItDown exceptions. You can catch this exception to handle any MarkItDown-related error.

Example

MissingDependencyException

Raised when a converter recognizes a file format but the required optional dependencies are not installed.

Inheritance

Inherits from MarkItDownException.

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

Raised when no suitable converter was found for the given file.

Inheritance

Inherits from MarkItDownException.

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

Raised when a suitable converter was found, but the conversion process fails.

Inheritance

Inherits from MarkItDownException.

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

FailedConversionAttempt

Represents a single failed attempt to convert a file. This is not an exception class, but a data class used by FileConversionException.

Constructor Parameters

Attributes

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.