Raising errors in Stateflow in accelerated model reference
Okay, so in Stateflow and in Matlab Function blocks, you can cause the smiulation to terminate with an error message by calling the error() function in an action. I have used this from time-to-time to detect fatal conditions that shouldn’t arise, it’s not really for common user errors but more like a failsafe.
The issue is: when the Stateflow is built into an accelerated model reference, the call to error() is just flat-out ignored. (I’d expect no less from The Mathworks than to decide it’s no big deal to just ignore calls to error() without even a warning. It’s not like that error statement was protecting against a buffer overrun or anything, or that it crashed Matlab for no apparent reason, or that we spent a whole day trying to debug the issue. But whatever, that’s not my question.)
We know not to rely on calling error() in Stateflow now, but we need a workaround.
The obvious solution is to have stateflow output a error_status flag, but then how to terminate the simulation with an error message?
Assertion Block is the only way I know of, but we don’t like this block for three reasons: 1. it can be disabled (since we’re protecting against a Matlab crash it’s not really a great idea to be able to disable it), 2.the error message it emits is not useful or customizable, and 3. the input to the assertion is considered a test point with no way to turn it off (so analyst will see all these assertion signals when reviewing data).
The Stop block will terminate the simulation but produces no error message.
I also tried using an S-function (figuring Mathworks can’t ignore errors hand-coded in C, no matter how much they want to), but that has a limitation that the model reference has to be single-instance.
So, any other ideas?Okay, so in Stateflow and in Matlab Function blocks, you can cause the smiulation to terminate with an error message by calling the error() function in an action. I have used this from time-to-time to detect fatal conditions that shouldn’t arise, it’s not really for common user errors but more like a failsafe.
The issue is: when the Stateflow is built into an accelerated model reference, the call to error() is just flat-out ignored. (I’d expect no less from The Mathworks than to decide it’s no big deal to just ignore calls to error() without even a warning. It’s not like that error statement was protecting against a buffer overrun or anything, or that it crashed Matlab for no apparent reason, or that we spent a whole day trying to debug the issue. But whatever, that’s not my question.)
We know not to rely on calling error() in Stateflow now, but we need a workaround.
The obvious solution is to have stateflow output a error_status flag, but then how to terminate the simulation with an error message?
Assertion Block is the only way I know of, but we don’t like this block for three reasons: 1. it can be disabled (since we’re protecting against a Matlab crash it’s not really a great idea to be able to disable it), 2.the error message it emits is not useful or customizable, and 3. the input to the assertion is considered a test point with no way to turn it off (so analyst will see all these assertion signals when reviewing data).
The Stop block will terminate the simulation but produces no error message.
I also tried using an S-function (figuring Mathworks can’t ignore errors hand-coded in C, no matter how much they want to), but that has a limitation that the model reference has to be single-instance.
So, any other ideas? Okay, so in Stateflow and in Matlab Function blocks, you can cause the smiulation to terminate with an error message by calling the error() function in an action. I have used this from time-to-time to detect fatal conditions that shouldn’t arise, it’s not really for common user errors but more like a failsafe.
The issue is: when the Stateflow is built into an accelerated model reference, the call to error() is just flat-out ignored. (I’d expect no less from The Mathworks than to decide it’s no big deal to just ignore calls to error() without even a warning. It’s not like that error statement was protecting against a buffer overrun or anything, or that it crashed Matlab for no apparent reason, or that we spent a whole day trying to debug the issue. But whatever, that’s not my question.)
We know not to rely on calling error() in Stateflow now, but we need a workaround.
The obvious solution is to have stateflow output a error_status flag, but then how to terminate the simulation with an error message?
Assertion Block is the only way I know of, but we don’t like this block for three reasons: 1. it can be disabled (since we’re protecting against a Matlab crash it’s not really a great idea to be able to disable it), 2.the error message it emits is not useful or customizable, and 3. the input to the assertion is considered a test point with no way to turn it off (so analyst will see all these assertion signals when reviewing data).
The Stop block will terminate the simulation but produces no error message.
I also tried using an S-function (figuring Mathworks can’t ignore errors hand-coded in C, no matter how much they want to), but that has a limitation that the model reference has to be single-instance.
So, any other ideas? model reference, accelerator, error MATLAB Answers — New Questions