Note that there are some explanatory texts on larger screens.

plurals
  1. POExpected behaviour? MATLAB ignores errors on deserialization, except when in debug mode
    text
    copied!<p>I don't understand Matlab's behaviour in the example below. On deserialization, it sets the properties of the object. This causes <code>set.name</code> to be executed. For the purpose of the example, I have constructed a case where an error is thrown in this method. In the first deserialization, the error is ignored and unhandled; the function simply stops execution at the error, code after the error is not executed. On the second deserialization, I have set <code>dbstop if error</code>, and now the error <em>is</em> triggered as I would expect. Questions follow below the example.</p> <pre><code>&gt;&gt; clear all; &gt;&gt; dbstatus; &gt;&gt; type Tester.m; classdef Tester &lt; handle properties name; end methods function self = Tester() disp('Creating Tester object'); end function set.name(self, val) global allnames if isequal(allnames, []) allnames = {}; end if any(strcmp(allnames, val)) fprintf(1, 'Name already exists. Will issue error.\n'); error('Error: duplicate name %s', val); fprintf(1, 'Still here?\n'); else self.name = val; allnames = [allnames self.name]; end end end end &gt;&gt; t = Tester(); Creating Tester object &gt;&gt; t.name = 'abc'; &gt;&gt; save('/tmp/fubar.mat', 't'); &gt;&gt; load('/tmp/fubar.mat') Name already exists. Will issue error. &gt;&gt; dbstop if error &gt;&gt; load('/tmp/fubar.mat') Name already exists. Will issue error. Error using Tester/set.name (line 18) Error: duplicate name abc 18 error('Error: duplicate name %s', val); K&gt;&gt; dbquit </code></pre> <ul> <li>Should I be surprised at this behaviour?</li> <li>Is this MATLAB™ being strange, or would other programming languages engage similar behaviour?</li> <li>Is there a good reason to behave like this?</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload