IllegalStateException errors

Hi support,

What is the straight and easiest way to avoid crashes in cases like : comments or footnotes in header&footer, page breaks or section breaks in table cells, etc, using Aspose.Word for java ?

Please advice,
Milan

Hi
Thanks for your request.

  1. You can use try catch statement to handle IllegalStateException exception. Something like the following:
try
{
    builder.insertBreak(BreakType.PAGE_BREAK);
}
catch (java.lang.IllegalStateException ex)
{
    // Do something.
}
  1. You can check whether you can insert break at current position. For example:
if (builder.getCurrentParagraph().getParentNode().getNodeType() == NodeType.BODY)
{
    builder.insertBreak(BreakType.PAGE_BREAK);
}
else
{
    // Do something.
}

Hope this helps.
Best regards.