MATLAB: Can I throw an empty MException object using THROW, RETHROW, or THROWASCALLER in MATLAB 7.12 (R2011a)

MATLAB

I want THROW, RETHROW and THROWASCALLER not displaying error message when an empty MException object is given.
When I execute:
function dummythrow
  errobj = MException.empty;
  throw(errobj);
end
I receive the following result:
??? Error using ==> throw
Parameter must be a scalar.
I want to THROW, RETHROW and THROWASCALLER behave like ERROR, not displaying the above error message when an empty MException object is given.
For example:
function errobj = MyIsEqual(a, b)
  errobj = MException.empty;
  if ~isequal(a, b)
    errobj = MException('CallerFunc:notIsEqual', 'Not equal.');
  end
end
a = 1;
error(MyIsEqual(a, 0));
throw(MyIsEqual(a, 0));
Is there any way to accomplish this?

Best Answer

The ability to throw an empty MException object using THROW, RETHROW and THROWASCALLER is not available in MATLAB. To work around this issue, use a condition statement to bypass the use of an empty MException Object:
errobj = MyIsEqual(params)
if isempty(errobj)
  % do nothing
else
  throwAsCaller(errobj)
end
Using condition statements whenever an empty MException object is given, however, may affect the conciseness of the code.