FUNCTION REFERENCE

catch

Handle an error from a try block.

Handle an error from a try block.

Syntax

try; statements; catch; handler; end

Syntax

try; statements; catch err; handler; end

Runs the handler only if the try block raises a catchable error. The optional err variable is a scalar struct with message, identifier and stack fields. Its stack is an empty 0-by-1 struct with file, name and line fields. An error in the handler propagates to an enclosing try block.

Example

try; error('plain msg'); catch err; disp(class(err)); end   % struct

Differences from MATLAB: The caught value is a struct, not an MException. Cancellation and execution limits cannot be caught.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.