Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Output an error message for executed command

1 visualizzazione (ultimi 30 giorni)
jinang patel
jinang patel il 23 Gen 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commento
Mohammad Sami
Mohammad Sami il 25 Gen 2020
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.

Risposte (1)

Walter Roberson
Walter Roberson il 25 Gen 2020
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

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by