Exceptions
This commit is contained in:
parent
073de6fbbf
commit
ce66178d75
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
11
try_catch.m
11
try_catch.m
|
|
@ -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
|
||||
Loading…
Reference in New Issue