1. Home
  2. /
  3. GroupDocs.Merger.LowCode
  4. /
  5. Developer Guide
  6. /
  7. Handling Errors

Handling Errors

The plugins report problems with exceptions from the GroupDocs.Merger.Exceptions namespace:

ExceptionWhen it is thrown
FileTypeNotSupportedExceptionThe source document doesn’t have the format of the plugin.
GroupDocsMergerExceptionThe operation can’t be performed, for example because a page number doesn’t exist in the document or no pages to remove were given.
MissingDependencyExceptionA component that the plugin needs is missing from the application or from the system. The document is not at fault.

A metered license issued for another plugin throws InvalidOperationException; see Licensing.

Handle an Unsupported Input Format

The following example passes a DOCX document to the SplitPdf plugin and prints the message of the exception.

using System;
using GroupDocs.Merger.Exceptions;
using GroupDocs.Merger.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

try
{
    // A DOCX document passed to the PDF plugin
    var splitter = new SplitPdf("business-plan.docx", new[] { 1 });
    splitter.Save("output/page.pdf");
}
catch (FileTypeNotSupportedException ex)
{
    // Input format does not match the expected format 'PDF'; the supplied file is ...
    Console.WriteLine(ex.Message);
}
Imports System
Imports GroupDocs.Merger.Exceptions
Imports GroupDocs.Merger.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        Try
            ' A DOCX document passed to the PDF plugin
            Dim splitter As New SplitPdf("business-plan.docx", {1})
            splitter.Save("output/page.pdf")
        Catch ex As FileTypeNotSupportedException
            ' Input format does not match the expected format 'PDF'; the supplied file is ...
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Module
open System
open GroupDocs.Merger.Exceptions
open GroupDocs.Merger.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    try
        // A DOCX document passed to the PDF plugin
        let splitter = SplitPdf("business-plan.docx", [| 1 |])
        splitter.Save("output/page.pdf")
    with :? FileTypeNotSupportedException as ex ->
        // Input format does not match the expected format 'PDF'; the supplied file is ...
        printfn "%s" ex.Message
    0

Handle Invalid Page Numbers

The following example tries to remove a page that doesn’t exist.

using System;
using GroupDocs.Merger.Domain.Options;
using GroupDocs.Merger.Exceptions;
using GroupDocs.Merger.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

try
{
    // The document has 18 pages
    var remover = new RemovePagesPdf("business-plan.pdf", new RemoveOptions(new[] { 50 }));
    remover.Save("output/trimmed.pdf");
}
catch (GroupDocsMergerException ex)
{
    // Page number more than page count.
    Console.WriteLine(ex.Message);
}
Imports System
Imports GroupDocs.Merger.Domain.Options
Imports GroupDocs.Merger.Exceptions
Imports GroupDocs.Merger.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        Try
            ' The document has 18 pages
            Dim remover As New RemovePagesPdf("business-plan.pdf", New RemoveOptions({50}))
            remover.Save("output/trimmed.pdf")
        Catch ex As GroupDocsMergerException
            ' Page number more than page count.
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Module
open System
open GroupDocs.Merger.Domain.Options
open GroupDocs.Merger.Exceptions
open GroupDocs.Merger.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    try
        // The document has 18 pages
        let remover = RemovePagesPdf("business-plan.pdf", RemoveOptions([| 50 |]))
        remover.Save("output/trimmed.pdf")
    with :? GroupDocsMergerException as ex ->
        // Page number more than page count.
        printfn "%s" ex.Message
    0

Missing Dependencies

MissingDependencyException means that the plugin couldn’t load a component it depends on. Its AssemblyName property names the assembly when it is known. Typical causes:

  • On Linux, the PPTX plugins need fontconfig and fonts. See Linux and macOS Dependencies.
  • The application was published with trimming or as a single file, and an assembly of the package was removed or can’t be loaded. Publish the application without trimming.