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

조회 수: 19 (최근 30일)
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.

채택된 답변

Walter Roberson
Walter Roberson 2014년 4월 2일
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
Leor Greenberger
Leor Greenberger 2014년 4월 2일
I was thinking that might be the only way. Thanks for your help.
vaka sindhu
vaka sindhu 2014년 4월 2일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by