Idea

Serge A avatar image
26 Likes"
Serge A suggested Serge A edited

Proper Exception Handling in FlexScript

FlexSim lacks means to signal, intercept and recognize errors and exceptional conditions. It's a serious issue, because Flexscript API is not exception safe.

Situations which may trigger exceptions are too many to make an exhaustive list. These are just a few of the top of my head:

  • Array index out of bounds
  • subnodes index out of bounds
  • invalid Table row/column
  • invalid cast (like a treenode without Object data to Object)
  • Variant.dataType on a non-treenode Variant
  • Variant.charAt on a non-string Variant
  • Object.stats.state(n) for legacy state profiles

That's not counting occasional bugs in FlexSim or in custom C++ extension modules.

None of these report:

  1. location (node, line, expression)
  2. stack trace
  3. the last consumed event

The major problem is:

  • the function where the exception happens exits immediately, and likely leaves the model in an inconsistent state;
  • but the simulation doesn't stop, it just keeps running;
  • and there is no mechanism to detect this.

In this example Source1 emits an item which is not properly configured (remains pink), and but the simulation happily goes on:

Redesigning the entire FlexScript API to be exception safe is not probably a realistic endeavor, so my proposal is to implement exception handling.

  1. stop simulations when an unhandled exception happens (don't consume any more events)
  2. report line and expression where the exception happened, display the stack trace
  3. allow to detect and handle exceptions in code (try-catch-finally, or similar)
flexscriptfeature requestexceptionsflexscript exception
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

No Comments

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.