Try for exception handling 
| ID | STAT-18 |
| Title | Only use the try construct for exception handling. |
| Priority | Strongly recommended |
| Severity level | 5 |
| Description | Only use the try construct for exception handling.An exception object must be assigned or created and an error function must be called in the catch.Do not use try/catch to suppress errors or to express simple conditions.There are other, more suitable options for that. |
| Rationale | Using try for simple error suppression can result in poor performance and unexpected behaviour. When a different error occurs than the one expected, it can go undetected because of the try/catch. |
Avoid:
try
nElems = container.nElements;
catch
nElems = 0;
end
Instead use:
if isfield(container, 'nElements')
nElems = container.nElements;
else
nElems = 0;
end