Handling password required exception

Signature class supports handling required password exception when opening protected documents over class PasswordRequiredException.

Here are the steps to handle incorrect password exception when working with protected documents with GroupDocs.Signature:

Following example demonstrates how to handle required password exception.

// skip initialization of LoadOptions with Password
// LoadOptions loadOptions = new LoadOptions(){ Password  = "1234567890" }    
Signature signature = new Signature("protectedPwd.pdf");
    QrCodeSignOptions options = new QrCodeSignOptions("JohnSmith");
    // try to sign document to file, we expect for PasswordRequiredException
    signature.sign(outputFilePath, options);
    System.out.print("\nSource document signed successfully.\nFile saved at " + outputFilePath);
catch(PasswordRequiredException ex)
    System.out.print("PasswordRequiredException: " + ex.getMessage());
catch(GroupDocsSignatureException ex)
    System.out.print("Common GroupDocsSignatureException: " + ex.getMessage());
catch (java.lang.RuntimeException ex)
    System.out.print("Common Exception happens only at user code level: " + ex.getMessage());

More resources

GitHub Examples 

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App 

Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App.