addCorrection

Attaches a suggested fix to an MException.

Category: Programming > Programming Utilities

Syntax

baseME = addCorrection(baseME, correction)

Returns a copy of baseME carrying the given correction object.

Description

A correction is a hint that an environment can offer to the user as a one-click fix next to the error. addCorrection stores it in the Correction property of the exception and leaves the message and identifier unchanged. The original object is not modified, so assign the result back.

Input arguments

baseME
The MException that reports the problem.
correction
A correction object that describes how the problem could be fixed.

Output arguments

baseME
The updated exception, with the Correction property set.

Example

Setting the Correction property

ME = MException('app:cfg', 'Missing option');
ME2 = addCorrection(ME, 1);
disp(ME2.message)
disp(isempty(ME.Correction))
disp(isempty(ME2.Correction))
Output
Missing option
   1
   0

Notes

MatLivre stores whatever object it receives in Correction and never offers it as an interactive fix.

See also

MException addCause throw getReport