Skip to content

addCause

Attach a cause exception to a base exception.

newME = addCause(baseME, causeME)

Returns a copy of baseME with causeME added to its causes list. Useful for chaining exceptions: re-throw a high-level error while preserving the underlying cause for diagnostic purposes.

try; foo; catch ME1;
ME2 = MException('MyApp:summary', 'foo failed');
ME2 = addCause(ME2, ME1);
throw(ME2);
end
  • MException — Construct an exception object.
  • throw — Throw a previously-constructed exception.
  • getReport — Format an exception object as a string.