plato/try_catch.m

11 lines
328 B
Matlab

clear
% matlab exceptions are represented by MException
try
non_existing + 3;
catch e
% identifier is the type of the exception
assert(isequal(e.identifier, 'MATLAB:UndefinedFunction'));
assert(isequal(e.message, 'Unrecognized function or variable ''non_existing''.'));
end
% throw is used to throw a MException