Info
此问题已关闭。 请重新打开它进行编辑或回答。
Output an error message for executed command
1 次查看(过去 30 天)
显示 更早的评论
Hello,
Is there is a way to return error message over mulitple expressions or do I need to split each expression into try & catch.
example code
try
exp1
..... exp 50
end
Expected Output
exp5 NOK
exp 20 NOK
1 个评论
Mohammad Sami
2020-1-25
I am not sure what you mean.
the try catch block will catch any exception. If the exception is in the first line of code, the rest of the code will not be executed. if there is no exception, then catch block will not be run.
回答(1 个)
Walter Roberson
2020-1-25
You need try/catch around the execution of each statement that needs separate handling.
If you are able to put the code for each into a function handle, then you can create a cell array of function handles and then loop
for idx = 1 : length(fncs)
try
fncs{idx}(arguments) ;
catch
report it
end
end
See also the Unit Test framework
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!