How to handle error in callback function triggered by an event?

Hi All,
I have an instance of a class I created that can trigger events. I have other classes that set listeners on this object and execute some stuff in a callback function. The callback function may do some error checking and use the error() function to raise an exception if there is an issue. What I was hoping for is that when this happens, that MATLAB would cease executing any remaining listeners as well as the function that triggered the event.
However, from the MATLAB documentation,
Callback function execution continues until the function completes. If an error occurs in a callback function, execution stops and control returns to the calling function. Then any remaining listener callback functions execute.
So what I can do to get around this? Should I be using something other than an event in this case?
Thanks.

 Accepted Answer

The order in which listeners callback functions execute after the firing of an event is undefined.
Which listeners are "remaining" is thus subject to change -- between releases at the very least, and plausibly the listener order could vary between events. The documentation speaks of the event being "broadcast" to all of the listeners; MATLAB has never defined the order in which competing interrupts (at the same level) are executed.
If you had the handles of the other listeners, you could set them disabled -- though it is not clear that would affect ones that had already been notified.
There are no documented tools to query or change the listener order, so abstractly at least, you are not intended to know or change the order.

4 Comments

Thanks Walter. Yes, I did read that part, so I understand disabling the remaining listeners might not be possible. I would be happy though if I were somehow able to tell the function/method that triggered the event to not continuing executing after control is returned back to it when an error/exception occurs in a callback function. Do you think this is possible?
I really couldn't say for sure, but my guess is No, not possible, at least not without cooperation (such as having the events listened to set a success flag and having the code check the flag before going onwards.)
I was thinking that might be the only way. Thanks for your help.
sir i am new to this matlab i want to satisfy the equation (512*512*log2(B))/>=520000 by keeping what value of B this equation will be satisfied answer is 16 .. i want how to do code for this equation in matlab by taking B values automatically to satisfy this equation

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!