cc @amjad.sahi: I tag you in this since you were very helpful in our last post and I appreciated your kind invitation to reach out again.
Hello dear forum,
# The issue:
I am having difficulties triggering aspose.cell Exceptions programmatically for a unit test.
# Context:
I’m working on adding test coverage for the PdfSaveOptions.setIgnoreError(true)
feature to ensure unhandled errors during conversion are ignored, and the rest of the document renders as expected.
However, despite consulting the ExceptionType reference, I cannot programmatically trigger exceptions in my test cases, even with setIgnoreError(false)
or omitting the setting entirely. While Excel raises error pop-ups when opening the generated files, no exceptions are thrown during conversion.
# Code Summary: Test Case: (Attempting to trigger exceptions like CHART, DATA_TYPE, etc.)
Workbook workbook = new Workbook();
Worksheet sheet = workbook.getWorksheets().get(0);
Cells cells = workbook.getWorksheets().get(0).getCells();
// Unsupported Chart Type (ExceptionType.CHART)
int chartIndexes = sheet.getCharts().add(ChartType.BUBBLE, 1, 1, 10, 10);
Chart chart = sheet.getCharts().get(chartIndexes);
chart.getNSeries().add("INVALID_SERIES", true);
// Invalid Data Type (ExceptionType.DATA_TYPE)
cells.get("B1").putValue(Double.POSITIVE_INFINITY);
// Invalid Data Validation (DATA_VALIDATION)
Validation validation = sheet.getValidations().get(sheet.getValidations().add());
validation.setType(ValidationType.DECIMAL);
validation.setFormula1("INVALID_FORMULA");
// Invalid Page Setup (PAGE_SETUP)
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setPaperSize(1234);
// Unsupported Shape (SHAPE)
Shape unsupportedShape = sheet.getShapes().addShape(MsoDrawingType.SMART_ART, 0, 0, 0, 0, 100, 100);
unsupportedShape.setName("UnsupportedShape");
// Invalid PivotTable (PIVOT_TABLE)
int pivotTableIndexes = sheet.getPivotTables().add("A1:E10", "G1", "InvalidPivot");
PivotTable pivotTable = sheet.getPivotTables().get(pivotTableIndexes);
pivotTable.addFieldToArea(PivotFieldType.ROW, 0);
pivotTable.setAutoFormatType(-1);
// Conversion
Path pdfPath = saveWorkbookToPdf(workbook);
Code Under Test: I’ve attached the code I’m testing. I’ve also checked if exceptions are suppressed, but the handling seems straightforward.
convertExcelToPDF method.zip (1.9 KB)
Observations:
- Files generated do produce Excel pop-ups when opened, indicating errors exist.
- No exception (e.g.,
CellsException
) is triggered duringworkbook.save(...)
, even withPdfSaveOptions.setIgnoreError(false)
.
# Request for Guidance:
- Am I correctly attempting to trigger exceptions for
PdfSaveOptions.setIgnoreError(false)
? - Are there specific conditions or scenarios needed to observe exceptions for these cases?
- Could anything in the code under test be inadvertently suppressing exceptions?
Thank you in advance for your time and expertise! Looking forward to your insights.
Best regards,
Ioan