Error handling

All conversion methods raise exceptions on failure. Use standard try/except with specific exception types:

from groupdocs.markdown import MarkdownConverter
from groupdocs.markdown import DocumentProtectedException, InvalidFormatException, GroupDocsMarkdownException

def error_handling_example():
    """Demonstrate error handling with specific exception types during conversion."""

    try:
        # Step 1: Attempt to convert the document
        MarkdownConverter.to_file("annual-report.docx", "error-handling.md")
    except DocumentProtectedException:
        # Step 2a: Handle password-protected documents
        print("Wrong or missing password.")
    except InvalidFormatException:
        # Step 2b: Handle corrupt or unsupported file formats
        print("File is corrupt or unsupported.")
    except GroupDocsMarkdownException as ex:
        # Step 2c: Handle any other conversion errors
        print(f"Conversion failed: {ex}")

if __name__ == "__main__":
    error_handling_example()

annual-report.docx is sample file used in this example. Click here to download it.

Output produced by this example (download):

[queryEmployees]

Employee Information for Employee [EmployeeID]: [FirstName] [LastName]

Employee Information

Job Title  AUTOTEXTLIST \t "<wr:out select='${varName1.Title}'/>" [Title]

Output produced by this example (download):

[queryEmployees]

Employee Information for Employee [EmployeeID]: [FirstName] [LastName]

Employee Information

Job Title  AUTOTEXTLIST \t "<wr:out select=’${varName1.Title}’/>" [Title]

[queryEmployees]

Employee Information for Employee [EmployeeID]: [FirstName] [LastName]


# Employee Information


| Job Title |  AUTOTEXTLIST  \t "<wr:out select='${varName1.Title}'/>" [Title] |
| --- | --- |
...

Download full output

[queryEmployees]

Employee Information for Employee [EmployeeID]: [FirstName] [LastName]


# Employee Information


| **Job Title** | **[Title]** |
| --- | --- |
[TRUNCATED]

Download full output

Exception types

ExceptionWhen raised
DocumentProtectedExceptionDocument is password-protected and no password or wrong password was provided
InvalidFormatExceptionFile is corrupt or has an unrecognized format
GroupDocsMarkdownExceptionGeneral conversion error

Conversion warnings

Non-fatal issues are reported via ConvertResult.warnings:

from groupdocs.markdown import MarkdownConverter, ConvertOptions

def warnings_example():
    """Show how to inspect non-fatal conversion warnings after converting."""

    # Step 1: Open the spreadsheet with a context manager
    with MarkdownConverter("cost-analysis.xlsx") as converter:
        # Step 2: Configure row truncation
        options = ConvertOptions()
        options.max_rows = 10  # limit to first 10 data rows per sheet

        # Step 3: Convert using keyword argument for options
        result = converter.convert("warnings.md", convert_options=options)

        # Step 4: Inspect non-fatal warnings (e.g., truncation notices)
        for warning in result.warnings:
            print(f"Warning: {warning}")

if __name__ == "__main__":
    warnings_example()

cost-analysis.xlsx is sample file used in this example. Click here to download it.

## Cost data and chart

|  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- |
|  |  | Cost Analysis |  |  |  |  |  |
|  |  | PARETO CHART |  |  |  |  |  |
|  |  | COST ANALYSIS |  |  |  |  | COST CENTER |
|  |  | Cost center | Annual cost  | Percent of total | Cumulative percent |  |  |
|  |  | Parts and materials | $1,325,000.00  | 31.17% | 31.17% |  |  |
|  |  | Manufacturing equipment | $900,500.00  | 21.19% | 52.36% |  |  |
...

Download full output

## Cost data and chart

|  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- |
|  |  | Cost Analysis |  |  |  |  |  |
|  |  | PARETO CHART |  |  |  |  |  |
|  |  | COST ANALYSIS |  |  |  |  | COST CENTER |
|  |  | Cost center | Annual cost  | Percent of total | Cumulative percent |  |  |
|  |  | Parts and materials | $1,325,000.00  | 31.17% | 31.17% |  |  |
|  |  | Manufacturing equipment | $900,500.00  | 21.19% | 52.36% |  |  |
[TRUNCATED]

Download full output