checkTryExceptionHandling
Run this check to check if all try
blocks are
only used for exception handling. Although not recommended,
try
statements could also be used to suppress
errors or to express a simple condition. checkTryExceptionHandling
checks the following for every try:
-
Is there a
catch
block with at least one line of executable code? -
Is an exception object assigned or created in the
catch
?-
Assigned:
catch`` ME
-
Created:
ME = MException(errorID, msg);
-
-
Is at least one of the list of exception handling MATLAB-installed functions or keywords used in the
catch
?
This does not check if points 2 and 3 hold for all execution paths
within the catch
, so if you use an
if
-else
within the
catch
and only call an exception handling
function in one of the two, it is not reported by this check.
Configurable parameters
-
RequireExceptionObject (boolean): When set to
true
(default), perform check 2. When set tofalse
, do not require an exception object to be assigned or created in thecatch
. -
ExceptionHandlingFunctions (list): List of functions or MATLAB keywords (
return
etc.), at least one of which must be called within everycatch
. The default list iserror
,throw
,rethrow
,throwAsCaller
. Other suggestions are:errordlg
,warning
,return
or some user-defined exception handling function.
Exemption tag: %@ok<TRYEH>