Aspose.Words API 'throws' declares only java.lang.Exception

Hi,

Basically this is duplicate of the issue logged in this post, but concerning Aspose.Words.

I’ll describe the problem again:

We’re using Aspose.Words API in our product (version: 14.1.0.0, released 31 Jan 2014) and all the public methods of the API that throw an exception, have signature like:

public SomeClass doStuff() throws Exception

This is very inconvenient for us to work with as we have no way to intercept exceptions that we know are thrown by Aspose API.
Now we’d have to either add a try/catch block around each Aspose API call (that’s quite a lot), or catch a java.lang.Exception higher in our code, analyze its message and guess somehow that it came from Aspose API.

So, to summarize, we’d like to see the public API have signatures like:

public SomeClass doStuff() throws AsposeException

Are there plans to implement this in one of the next releases? Any estimate would be very appreciated.

Kind regards,

Ekaterina

Hi Ekaterina,

Thanks for your inquiry.

It would be great if you please share the APIs for which you are getting the exception. There might be some generic exception or specific exceptions are thrown while using Aspose.Words APIs. E.g Document Constructor (Stream) may throws following type of exceptions.

UnsupportedFileFormatException The document format is not recognized or not supported.
FileCorruptedException The document appears to be corrupted and cannot be loaded.
Exception There is a problem with the document and it should be reported to Aspose.Words developers.
IOException There is an input / output exception.
IncorrectPasswordException The document is encrypted and requires a password to open, but you supplied an incorrect password.
ArgumentNullException The stream cannot be null.
NotSupportedException The stream does not support reading or seeking.
ObjectDisposedException The stream is a disposed object.

Hi Tahir,

Thanks for your reply. Below are some simple code samples:

try
{
    Document document = new Document(inputStream);
}
catch (Exception e)
{
    e.printStackTrace();
}

try
{
    document.updatePageLayout();
}
catch (Exception e)
{
    e.printStackTrace();
}

try
{
    document.save("/Users/test-user/output.pdf", new PdfSaveOptions());
}
catch (Exception e)
{
    e.printStackTrace();
}

The problem is that there’s no way for us to know what various types of exceptions does this or that method throw, because:

  1. the signature of the method declares ‘throws Exception’
  2. The Java API reference on the website does not document the exception types for the methods. I went to check Document constructor documentation and it does not say anything about what exceptions it might throw.

So, for example, we’d expect Document constructor to be like:

Document (InputStream stream) throws UnsupportedFileFormatException, FileCorruptedException, IOException, IncorrectPasswordException, ArgumentNullException, NotSupportedException, ObjectDisposedException

Kind regards,

Ekaterina

Hi Ekaterina,

Thanks for sharing the detail.

We have logged this issue in our issue tracking system for consideration. Aspose.Word should not throw any generic exception and the exceptions should be specific e.g AsposeException.

I have logged this issue as WORDSJAVA-844 in our issue tracking system. Our development team will look into the possibility of implementation. Once we have any information about this issue, we will update you via this thread.

Please let us know if you have any more queries.

Hi Ekaterina,

Thanks for your patience. It is to update you that we have closed the issue (WORDSJAVA-844) with “Not a bug” resolution.

  1. Most Aspose.Words public methods actually throws 10+ exceptions.
  2. Moreover, actual possible exceptions are dependent on workflow e.g. if you save document to PDF you will get the one set of exceptions but if you save document to PNG you will get another set of exceptions.
  3. Some Exceptions are dependent on host platform: Windows+OracleJVM in particular place can throw different exception than Linux+IBM_JVM.

So, there is no need to add 10-20 redundant try-catch blocks for every Aspose.Words method.