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

30 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de Abr. de 2014
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 comentarios
Leor Greenberger
Leor Greenberger el 2 de Abr. de 2014
I was thinking that might be the only way. Thanks for your help.
vaka sindhu
vaka sindhu el 2 de Abr. de 2014
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

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by