Can "Pause on Errors" be enabled by a script, or set as the default?

I run many processes that take a day or more to run, and sometimes they encounter unexpected errors. I don't always think to turn on "Pause on Errors", but when an error ocurrs, I wish that I had. Is there a way to set this in my script, or configue MATLAB such that this is the default behavior?

 Respuesta aceptada

dbstop if error
It is sometimes useful to use
dbstop if caught error
However, it turns out that caught errors are expected in routines such as ode45() and integrate() so it can get a bit frustrating to deal with all the caught errors sometimes.

3 comentarios

If you only wanted to stop at a catch block in your own code (not MathWorks code), as long as you have a small number of them, you could use the dbstop in <file> at <location> command once per catch block (hence "small number of them") to stop on the first executable line inside the catch block.
Or if you always wanted to stop in the catch block, without worrying about the specific line number where the try / catch occurs, you could call a helper function that does nothing but has an executable line in it (1+1; for example) at the start of the catch block and set a breakpoint to stop in that helper function on that line (which is unlikely to change.) Or if you always want MATLAB to enter debug mode in that case, call keyboard as the sole line in that helper function (or just call keyboard in the catch block.)
If you use a helper function you'd need to change workspaces as part of your debugging.
function anchorForStopping % in anchorForStopping.m
1+1; % or keyboard;
end
I appreciate the comments and insights. Thank you very much.
But my code is designed to run in deployed mode, and try/catch is not compatible with the MATLAB coder, so I cannot use this construct.
Pausing on error is not compatible with MATLAB Coder.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Desktop en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Preguntada:

el 15 de Oct. de 2024

Comentada:

el 4 de Nov. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by