Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

MATLAB Basics: Using dbstop if error 3

Posted by Doug Hull,

When MATLAB throws an error, if you are in a function, you will end up at the base workspace and lose access to the variables as they were in the function when the error was thrown. This makes it difficult to understand why the error occurred. With the debugger, MATLAB can stop when the error is thrown, so the variables are still in scope. This makes debugging much easier.

3 CommentsOldest to Newest

Eric S replied on : 1 of 3
It would be great to stop the debugger from coughing somewhere inside the more "internal" functions. Is there a way to specify not to barf in certain directories, or in the ones you're developing in only? Cheers, Eric
Morrison Lucas replied on : 2 of 3
Hear hear! I generally have one set of files that I'm debugging, and desire the "dbstop if error" functionality for files in that set. Everything else I don't want to hear about, just give me the error message and let's move on. In terms of the interface, one possibility would be to implement the following calling convention: DBSTOP in MFILE if error As well as the "caught error", "warning" variants. -Mory
Doug replied on : 3 of 3
Mory, I understand what you are looking for in an abstract way, but I am having some problems with understanding particulars. If I am writing code, the bad code might be in *my* code, but might not manifest until a deep call, ie sum('a', 1) %let's pretend this code caused an error in SUM Would you want to stop? The 'error' is thrown by SUM which is not in your directory, so should it be skipped or not? I personally want it to stop and then just run up the stack until I get to *my* code. Like I said, I think there is something to this suggestion, but I am not sure what would cause a DBSTOP and what would not. -Doug

Add A Comment

Your email address will not be published. Required fields are marked *

Preview: hide