Error handling

Error handling

All Convert() methods throw on failure. Use standard try/catch with specific exception types:

using GroupDocs.Markdown;

try
{
    string md = MarkdownConverter.ToMarkdown("file.docx");
    Console.WriteLine(md);
}
catch (DocumentProtectedException)
{
    Console.WriteLine("Wrong or missing password.");
}
catch (InvalidFormatException)
{
    Console.WriteLine("File is corrupt or unsupported.");
}
catch (GroupDocsMarkdownException ex)
{
    Console.WriteLine($"Conversion failed: {ex.Message}");
}

Exception types

ExceptionWhen thrown
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:

using GroupDocs.Markdown;

using var converter = new MarkdownConverter("data.xlsx");
ConvertResult result = converter.Convert(new ConvertOptions { MaxRows = 10 });

Console.WriteLine(result.Content);

foreach (string warning in result.Warnings)
    Console.WriteLine($"Warning: {warning}");