MException
Exception information.
📝Syntax
ME = MException(identifier, message)
ME = MException(identifier, format, A, ...)
ME = addCause(ME, causeException)
ME = ME.addCause(causeException)
ME = addCorrection(ME, correction)
report = getReport(ME)
report = ME.getReport(type)
exception = MException.last
MException.last('reset')
📥Input Arguments
Parameter Description
identifier a string: error identifier.
message a string.
format a string used to format the error message.
causeException a scalar MException object.
correction a nelson.lang.correction object.
type 'basic' or 'extended'.
📤Output Arguments
Parameter Description
ME a MException object.
report a string: formatted exception report.
📄Description

All Nelson code that detects an error and throws an exception constructs an MException object.

identifier includes one or more component fields and a mnemonic field (example: 'nelson:matrix:empty').

MException is a built-in class. It has the read-only properties identifier, message, cause, stack, and Correction.

ME = MException(identifier, format, A, ...) formats the message using the same formatting rules as sprintf.

addCause returns a new MException object with an additional cause.

addCorrection returns a new MException object with a correction object. Nelson correction objects are in the nelson.lang.correction package.

getReport returns a formatted exception report.

MException.last returns the last uncaught exception recorded by the evaluator. MException.last('reset') clears it.

💡Examples
ME = MException('nelson:identifier', 'your error message.');
throw(ME)
ME = MException('nelson:badIndex', 'Unable to index into array %s.', 'A');
causeException = MException('nelson:badSubscript', 'Index must be positive.');
ME = ME.addCause(causeException)
getReport(ME, 'basic')
ME = MException('nelson:missingArgument', 'Missing argument.');
correction = nelson.lang.correction.AppendArgumentsCorrection('value');
ME = addCorrection(ME, correction)
ME.Correction
🔗See Also
errortrythrowrethrowthrowAsCalleraddCauseaddCorrectiongetReportMException.lastlasterror
🕔Version History
Version Description
1.0.0 initial version
Edit this page on GitHub