Try-Catch clause fails in evalin

3 Ansichten (letzte 30 Tage)
Ryan
Ryan am 29 Nov. 2017
Beantwortet: Walter Roberson am 30 Nov. 2017
Wondering if someone knows why try-catch syntax fail to work inside an evalin('caller',expression)? Are there any workarounds? Additionally, the following doesn't work, although I kind of expected it to.
try
evalin('caller',expression1);
catch E
evalin('caller',expression2);
end
My reason for even wanting to use these horrible statements (bad code practice) is to write a save function wrapper that by default picks faster compressionless saves unless it fails (usually for reasons of file size for compressionless save). And of course variables for the save() process are in the calling workspace.
  2 Kommentare
Matt J
Matt J am 29 Nov. 2017
What "failure" do you see? How does it manifest?
Ryan
Ryan am 30 Nov. 2017
Ah, my bad. Should have included that. In essence it throws the error as if there's no catch statement.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 30 Nov. 2017
It does appear to generally work:
>> try; evalin('base','fooor'); catch ME; disp('caught'); end
caught
However, there are some errors that cannot be caught, including running out of memory and exceeding the recursion limit.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by