rethrow
Raises an exception again, usually from inside a catch block.
Category: Programming > Programming Utilities
Syntax
rethrow(ME)
Throws the exception ME with its original identifier and message.
rethrow(errStruct)
Throws an error described by a structure with message and identifier fields.
Description
A catch block that handles part of a problem, such as releasing a resource, can pass the error on to its caller with rethrow(ME) instead of hiding it. The caller then sees the original identifier and message.
Input arguments
ME- An
MExceptionobject. errStruct- Structure with at least the fields
messageandidentifier.
Example
Cleaning up, then passing the error on
try
try
error('io:fail', 'disk error')
catch inner
disp('cleaning up')
rethrow(inner)
end
catch outer
disp(outer.identifier)
end
Output
cleaning up
io:fail