What exceptions could workbook.Open(...) throw?


#1

On the server-side, using Aspose.Cells, I need a way to determine whether a memory stream passed to workbook.Open is Excel data and not some other type of file content. What is the best way to do this in Aspose? What exceptions could be thrown (for all error cases) by workbook.Open? Thanks.


#2

In code, I need to be able to distinguish between an exception caused by a user error (the user tried to open a non-Excel document) and internal errors reading a stream. Unfortunately, when I deliberately pass a stream whose content-type was "application/octet-stream" -- for example, an MSI file -- Aspose throws a null reference exception:

[System.NullReferenceException] = {"Object reference not set to an instance of an object."}


#3

Currently Aspose.Cells let your specify the file format and it reads file as Excel files. So please try catch all exceptions:

try

{

workbook.Open(stream);

}

catch

{

//do something here

...

}

In the future release, Aspose.Cells will check the file format and throw ExcelException if finding non-Excel files.


#4

That is what I am doing now, and it's where a null reference exception is thrown by Aspose whenever a non-Excel file data is passed as an argument.

I am glad that you will be defining Aspose-specific exception types. This would be good to do through-out the library so that clients of the library can properly catch and handle user errors and log exceptions that should not occur.

Thanks.