cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Proper Exception Handling in FlexScript

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:

9385-exception-nodefunction-terminates-half-way.png

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)

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea