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:
- location (node, line, expression)
- stack trace
- 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.
- stop simulations when an unhandled exception happens (don't consume any more events)
- report line and expression where the exception happened, display the stack trace
- allow to detect and handle exceptions in code (try-catch-finally, or similar)