Note that there are some explanatory texts on larger screens.

plurals
  1. PODebugging back to original error with conditional exception handling, i.e. rethrow
    primarykey
    data
    text
    <p>In Matlab, there is, as far as I know, no good way to conditionally catch exceptions (correct me if I'm wrong). The only way is to catch the exception, check the identifier, and rethrow the error if this particular error can not be handled. That's acceptable though inconvenient. However, when I use Matlabs <code>dbstop if error</code>, I end up at the <code>ME.rethrow()</code> line. I'm then unable to <code>dbup</code> back to the place where the <em>original</em> error was caused.</p> <pre><code>function test_excc try sub_test() catch ME if strcmp(ME.identifier, 'test:notsobad') fprintf(1, 'Fine\n'); else ME.rethrow(); end end end function sub_test sub_sub_test(); end function sub_sub_test() if rand&gt;0.5 error('test:error', 'Noooo!'); else error('test:notsobad', 'That''OK'); end end </code></pre> <p>Example usage:</p> <pre><code>&gt;&gt; test_excc() Error using test_excc&gt;sub_sub_test (line 21) Noooo! Error in test_excc&gt;sub_test (line 16) sub_sub_test(); Error in test_excc (line 4) sub_test() 9 ME.rethrow(); K&gt;&gt; dbstack &gt; In test_excc at 9 </code></pre> <p>Although the Matlab desktop environment prints the entire stack trace back to <code>sub_sub_test</code>, the debugger does not give me the possibility to go up the stack trace and debug inside this function.</p> <p>I am aware of <code>dbstop if caught error</code>. However, this will debug into <em>any</em> caught error, which may be many if software makes heavy use of exceptions. I only want to stop on uncaught errors, but I want to stop where the error is generated — not where it's rethrown.</p> <p>My question:</p> <ul> <li>In Matlab, how do I conditionally catch an error (based on error identifier) and debug into the place where the error is originally thrown?</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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