You can also use:
throw(MException('Id:id','message'));
There is a nice function for MException , it can be used as sprintf :
throw(MException('Foo:FatalError',... 'First argument of Foo is %s, but it must be double',class(varargin{1}) ));
As @edric correctly comments, this sprintf functionality can be a double sword. If you use some escape characters, this may not behave the way you want it to.
throw(MException('Foo:FatalError',... 'I just want to add a \t, no tab!' ));
source share