0. 消息标识符(Message Identifiers)

消息标识符,是附加在 error 和 warning 语句上的一个标签,以被 matlab 做唯一性标识。

warning 语句所支持的函数重载中,便可接收消息标识符,以警告信息的形式进行在控制台输出:

warning(msgID, ___)

一个简单的标识符的格式为:component:mnemonic,用冒号隔开;

matlab 内置的消息标识符为:

MATLAB:rmpath:DirNotFound
MATLAB:odearguments:InconsistentDataType
Simulink:actionNotTaken
TechCorp:OpenFile:notFoundInPath

1. warning(警告)

warning('off', '*:*:*');

2. 异常

try,catch

A = rand(3);
B = ones(5);

try
   C = [A; B];
catch ME
   if (strcmp(ME.identifier,'MATLAB:catenate:dimensionMismatch'))
      msg = ['Dimension mismatch occurred: First argument has ', ...
            num2str(size(A,2)),' columns while second has ', ...
            num2str(size(B,2)),' columns.'];
        causeException = MException('MATLAB:myCode:dimensions',msg);
        ME = addCause(ME,causeException);
   end
   rethrow(ME)
end