AnswerHub Upload Issue
Our AnswerHub community currently has a bug that prevents you from attaching your model or other files to your questions. AnswerHub is aware of this issue and they are working on a fix. Until we receive their patch, you can upload your models and other files to FlexSim's file share site. Include the file name in your question so that we know which upload to reference.

Idea

Serge A avatar image
22 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

·

Write a Comment

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

Your Opinion Counts

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