逃离嵌套的try - catch语句 [英] Escape from nested try - catch statement

查看:137
本文介绍了逃离嵌套的try - catch语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我现在可以使用 dbstop 命令,但每次看代码并想停止运行程序时,我必须为每个嵌套级别输入一次 dbquit



这是非常烦人的,我正在寻找一个解决方案,一旦完成调试,真的停止调试所有程序。



这是一个例如我如何调用代码:

  dbstop if error 
dbstop if catch error
mytestmain

这里是一个例子,该函数可以是什么样的(子功能可能是也可能不是在一个不同的.m文件)

  function mytestmain 
try
mytestsub
catch
end

%%子函数的定义
函数mytestsub
try
a = b;%生成错误b没有定义
catch
end



< hr>

我尝试了什么?




  • 我尝试使用一个脚本或一个调用的函数 dbquit 两次,但这只会执行 dbquit 一次。

  • 使用 dbquit('all'),但不起作用






请注意,我不想删除代码中的try-catch语句。

解决方案

在使用 dbquit

dbclear > dbclear all; dbquit;

但是,请注意,这也将清除您手动设置的所有断点,因此,如果使用断点此外,您应该使用

  dbclear如果错误; dbclear如果捕获错误; dbquit; 


I am currently debugging code with nested try-catch statements.

I can easily handle the errors with the dbstop command, but each time I look at the code and want to stop running the program, I have to enter dbquit once for each nesting level.

As this is quite annoying I am looking for a solution to really stop debugging all programs once I am done debugging.

Here is an example of how I call the code:

dbstop if error
dbstop if caught error
mytestmain

And here is an example of what the function could look like (the subfunction may or may not be in a different .m file)

function mytestmain 
try
    mytestsub
catch
end

%% Definition of subfunction
function mytestsub
try
    a=b;%generate an error as b is not defined
catch
end


What have I tried?

  • I tried using a script or a function that calls dbquit twice, however this will only execute dbquit once.
  • I tried using dbquit('all'), but with no effect

Note that I prefer not to remove the try-catch statements in the code.

解决方案

You could call dbclear before using dbquit

dbclear all; dbquit;

Note, however, that this will also clear all breakpoints you set manually, hence, if you use breakpoints in addition, you should rather use

dbclear if error; dbclear if caught error; dbquit;

这篇关于逃离嵌套的try - catch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆