Main Content

addCorrection

Provide suggested fix for exception

Description

meNew = addCorrection(meBase,meCorrection) creates a meNew MException object from the meBase MException and the suggested fix meCorrection. To construct meNew, addCorrection makes a copy of meBase and appends meCorrection to the meNew.Correction property.

example

meBase = addCorrection(meBase,meCorrection) modifies the existing meBase MException object by appending meCorrection to its Correction property.

Examples

collapse all

The function hello requires one input argument. Add a suggested input argument "world" to the error message.

function hello(audience)
if nargin < 1
    me = MException('MATLAB:notEnoughInputs', 'Not enough input arguments.');
    aac = matlab.lang.correction.AppendArgumentsCorrection('"world"');
    me = me.addCorrection(aac);
    throw(me);
end
fprintf("Hello, %s!\n", audience);
end

Call the function without an argument.

hello
Error using hello (line 6)
Not enough input arguments.

Did you mean:
>> hello("world")

Input Arguments

collapse all

Error information, specified as an MException object.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2019a