How to get Matlab stop on my file upon error?

21 ビュー (過去 30 日間)
Mark Golberg
Mark Golberg 2022 年 4 月 14 日
コメント済み: Matt J 2022 年 4 月 19 日
Hi,
in old Matlab version I could use "stop on error" under "Run" commend. Execution would stop prior to executing a command that will result in error. Very usefull feature when trying to debug your code.
Currently I'm using MATLAB 2021b, and if error occurs it open usually an extra one/two MATLAB inner files (see snapshot attached).
Is there away to configure it somehow to work as in older versions? I want matlab to halt before the error, to have all the variables in the WS, etc..
  32 件のコメント
Bruno Luong
Bruno Luong 2022 年 4 月 18 日
編集済み: Bruno Luong 2022 年 4 月 18 日
"How can I get into "moose1.m" function WS where the error actually occured?"
You can't since the error of moose is embeded in try/catch block and it is retrow by the calling function. So there is no lower level in the stack when the debugger stops. You can however recall mose or invoke the callback in the try block, but this is not convenient and you are never sure too reproduce the same effect/error with your function that would not reproduce the same thing from call to call (for example if it's depend on some random generated data or persistent variable, global variable, timer, etc...).

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2022 年 4 月 17 日
編集済み: Bruno Luong 2022 年 4 月 17 日
The problem has been solved in R2022a.
Under R2021b here is the stack when debugger stops, one can see there is a dirty try/catch in the App callback engine that prevent the dbstop occurs at user level. This try/catch is no longer in R2022a App callbcak engine.
There is then no workaround for R2021b (unless modify the App calback engine AppManagementService.m but is extremely dangerous)
>> app1
>> edit moose
Index in position 1 exceeds array bounds. Index must not exceed 10.
Error in moose (line 5)
m = a(11 , 1);
Error in app1/ButtonPushed (line 14)
moose
236 throw(callbackException);
K>> dbstack
> In appdesigner.internal.service/AppManagementService/tryCallback (line 236)
In matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 37)
In matlab.ui.control.internal.controller/ComponentController/executeUserCallback (line 427)
In matlab.ui.control.internal.controller/ComponentController/handleUserInteraction (line 381)
In matlab.ui.control.internal.controller/PushButtonController/handleEvent (line 86)
In appdesservices.internal.interfaces.controller/AbstractController/handleProxyViewEvent (line 279)
In appdesservices.internal.interfaces.controller.AbstractController>@(src,event)handleProxyViewEvent(obj,src,event) (line 207)
In appdesservices.internal.interfaces.view/AbstractProxyView/notify (line 117)
In appdesservices.internal.peermodel/PeerNodeProxyView/handlePeerEventFromClient (line 268)
In appdesservices.internal.peermodel.PeerNodeProxyView>@(varargin)obj.handlePeerEventFromClient(varargin{:}) (line 81)
In viewmodel.internal.factory.ManagerFactoryProducer>@(src,event)callback(src,viewmodel.internal.factory.ManagerFactoryProducer.convertStructToEventData(event)) (line 105)
K>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.11.0.1873467 (R2021b) Update 3
MATLAB License Number: xxxxxx
Operating System: Microsoft Windows 8.1 Pro Version 6.3 (Build 9600)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.11 (R2021b)
MATLAB Coder Version 5.3 (R2021b)
MATLAB Compiler Version 8.3 (R2021b)
Optimization Toolbox Version 9.2 (R2021b)
Signal Processing Toolbox Version 8.7 (R2021b)
K>>
Here is the same output with R2022a, it stops on moose.m
> app1
>> edit moose.m
>> dbstop if error
Index in position 1 exceeds array bounds. Index must not exceed 10.
Error in moose (line 5)
m = a(11 , 1);
Error in app1/ButtonPushed (line 14)
moose
Error in appdesigner.internal.service.AppManagementService/executeCallback (line 138)
callback(appOrUserComponent, event);
Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
newCallback = @(source, event)executeCallback(appdesigner.internal.service.AppManagementService.instance(), ...
5 m = a(11 , 1);
K>> dbstack
> In moose (line 5)
In app1/ButtonPushed (line 14)
In matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
K>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.12.0.1884302 (R2022a)
MATLAB License Number: xxxxxx
Operating System: Microsoft Windows 11 Home Version 10.0 (Build 22000)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.12 (R2022a)
MATLAB Coder Version 5.4 (R2022a)
MATLAB Compiler Version 8.4 (R2022a)
Optimization Toolbox Version 9.3 (R2022a)
Signal Processing Toolbox Version 9.0 (R2022a)
K>>

その他の回答 (1 件)

Matt J
Matt J 2022 年 4 月 16 日
編集済み: Matt J 2022 年 4 月 16 日
If you execute at the command line,
>> dbstop if caught error
and then rerun the app, I think you will find that the debugger stops where you want.
  3 件のコメント
Matt J
Matt J 2022 年 4 月 19 日
also make the problem to stop at a whole pack of new "matlab internal issues" that I was completely transpernat to them previously
Don't see why that would happen, unless you have lots of your own try-catch statements in the user-supplied code.

サインインしてコメントする。

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by