Exceptions

This commit is contained in:
Enrico Lumetti 2021-04-30 00:42:25 +02:00
parent 073de6fbbf
commit ce66178d75
2 changed files with 14 additions and 0 deletions

View File

@ -9,6 +9,9 @@ char_array = 'abc';
assert(all(char_array == ['a' 'b' 'c']));
assert(all(size(char_array) == [1 3]));
% single quotes are escaped by doubling
escaped = 'this is a ''char array'''; % this is a 'char array'
char_matrix = ['abc'; 'def'];
assert(numel(char_matrix) == 6);

View File

@ -0,0 +1,11 @@
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