Thread Subject: "Error using ==> dbstop"

Subject: "Error using ==> dbstop"

From: Martin

Date: 25 Jun, 2009 13:58:01

Message: 1 of 17

Hello everybody,

I am using the "publish" command to evaluate an *.m file and publish it as HTML. I then use the "lasterror" command to decide if the *.m file compiles correctly or contains errors.
I used this file for a couple of months and it worked. But now, I will receive following error message:

"Error using ==> dbstop
You can not set a breakpoint past the start of the last expression in the file."

Does anybody know what this means?
Best regards,

Martin

Subject: "Error using ==> dbstop"

From: Rune Allnor

Date: 25 Jun, 2009 14:17:10

Message: 2 of 17

On 25 Jun, 15:58, "Martin " <ro...@mrt.uka.de> wrote:
> Hello everybody,
>
> I am using the "publish" command to evaluate an *.m file and publish it as HTML. I then use the "lasterror" command to decide if the *.m file compiles correctly or contains errors.
> I used this file for a couple of months and it worked. But now, I will receive following error message:
>
> "Error using ==> dbstop
> You can not set a breakpoint past the start of the last expression in the file."
>
> Does anybody know what this means?

Unless the English language has changed over the past
couple of hours, it means that a breakpoint is attempted
set somwhere near the end of the file, after the last
expression in the file.

*Why* that happens is a completely different question.

Rune

Subject: "Error using ==> dbstop"

From: Martin

Date: 29 Jun, 2009 06:30:03

Message: 3 of 17

> Unless the English language has changed over the past
> couple of hours, it means that a breakpoint is attempted
> set somwhere near the end of the file, after the last
> expression in the file.
>
> *Why* that happens is a completely different question.

As an additional information: I never used breakpoints in these fiels at all! I also tried to delete all breakpoints, in "Matlab>Debug>Clear Breakpoints in All Files".

I appreciate any ideas!
Martin

Subject: "Error using ==> dbstop"

From: us

Date: 29 Jun, 2009 08:35:02

Message: 4 of 17

"Martin " <roser@mrt.uka.de> wrote in message <h29n1b$51j$1@fred.mathworks.com>...
> > Unless the English language has changed over the past
> > couple of hours, it means that a breakpoint is attempted
> > set somwhere near the end of the file, after the last
> > expression in the file.
> >
> > *Why* that happens is a completely different question.
>
> As an additional information: I never used breakpoints in these fiels at all! I also tried to delete all breakpoints, in "Matlab>Debug>Clear Breakpoints in All Files".
>
> I appreciate any ideas!
> Martin

a few thoughts (only)
- did you recently edit one of the files...
- did you MLINT your files to look for (minute) errors, eg, END/RETURN mismatches...
- how do you set the CATCHERROR option in publish...
- which ML version do you use...

us

Subject: "Error using ==> dbstop"

From: Martin

Date: 29 Jun, 2009 10:42:00

Message: 5 of 17

> a few thoughts (only)
> - did you recently edit one of the files...
> - did you MLINT your files to look for (minute) errors, eg, END/RETURN mismatches...
> - how do you set the CATCHERROR option in publish...
> - which ML version do you use...

Hi us,
thank you for your fast reply.
- MLINT does not find any errors.
- CATCHERROR=true
- I use MATLAB 7.8.0 (R2009a)

I created a simple example that will throw the error. I have no idea why the example below won't work!!!

1) the code I want to test:

function test()
a=1;
b=2;
fprintf('a+b=%d\n',a+b)
end

2) my evaluation code:

function evaluateTest()
clear all,close all,clc;
mFile='test.m'
opts.outputDir = fullfile('.');
opts.catchError=true
[MLINTinfo]=mlint(mFile)
publish(mFile, opts);
checkErrors=lasterror;
message = checkErrors.message
if(~isempty(message))
    fprintf('\nThere is an ERROR!\n');
end

3) evaluateTest() produces following output:

mFile =
test.m
opts =
     outputDir: '.'
    catchError: 1
MLINTinfo =
0x0 struct array with fields:
    message
    line
    column
message =
Error using ==> dbstop
You can not set a breakpoint past the start of the last
expression in the file.

There is an ERROR!


Best regards,
Martin

Subject: "Error using ==> dbstop"

From: Martin

Date: 29 Jun, 2009 10:45:03

Message: 6 of 17

one addition:
The published HTML contains no error:

function test()
a=1;
b=2;
fprintf('a+b=%d\n',a+b)
end

a+b=3


Published with MATLAB? 7.8

Subject: "Error using ==> dbstop"

From: us

Date: 29 Jun, 2009 11:36:01

Message: 7 of 17

"Martin " <roser@mrt.uka.de> wrote in message <h2a5po$amq$1@fred.mathworks.com>...
> > a few thoughts (only)
> > - did you recently edit one of the files...
> > - did you MLINT your files to look for (minute) errors, eg, END/RETURN mismatches...
> > - how do you set the CATCHERROR option in publish...
> > - which ML version do you use...
>
> Hi us,
> thank you for your fast reply.
> - MLINT does not find any errors.
> - CATCHERROR=true
> - I use MATLAB 7.8.0 (R2009a)
>
> I created a simple example that will throw the error. I have no idea why the example below won't work!!!
>
> 1) the code I want to test:
>
> function test()
> a=1;
> b=2;
> fprintf('a+b=%d\n',a+b)
> end
>
> 2) my evaluation code:
>
> function evaluateTest()
> clear all,close all,clc;
> mFile='test.m'
> opts.outputDir = fullfile('.');
> opts.catchError=true
> [MLINTinfo]=mlint(mFile)
> publish(mFile, opts);
> checkErrors=lasterror;
> message = checkErrors.message
> if(~isempty(message))
> fprintf('\nThere is an ERROR!\n');
> end
>
> 3) evaluateTest() produces following output:
>
> mFile =
> test.m
> opts =
> outputDir: '.'
> catchError: 1
> MLINTinfo =
> 0x0 struct array with fields:
> message
> line
> column
> message =
> Error using ==> dbstop
> You can not set a breakpoint past the start of the last
> expression in the file.
>
> There is an ERROR!
>
>
> Best regards,
> Martin

the evaluateTest() should read as follows

function etest()
     mFile='test.m';
     opts.outputDir='.';
     opts.catchError=true;
try
     publish(mFile,opts);
catch msg
     error(msg.message);
end
end

% at the command prompt
     etest;
% no errors
     web('test.html');
% shows function AND result

us

Subject: "Error using ==> dbstop"

From: Loren Shure

Date: 29 Jun, 2009 11:44:45

Message: 8 of 17

In article <h2a5po$amq$1@fred.mathworks.com>, roser@mrt.uka.de says...
> > a few thoughts (only)
> > - did you recently edit one of the files...
> > - did you MLINT your files to look for (minute) errors, eg, END/RETURN mismatches...
> > - how do you set the CATCHERROR option in publish...
> > - which ML version do you use...
>
> Hi us,
> thank you for your fast reply.
> - MLINT does not find any errors.
> - CATCHERROR=true
> - I use MATLAB 7.8.0 (R2009a)
>
> I created a simple example that will throw the error. I have no idea why the example below won't work!!!
>
> 1) the code I want to test:
>
> function test()
> a=1;
> b=2;
> fprintf('a+b=%d\n',a+b)
> end
>
> 2) my evaluation code:
>
> function evaluateTest()
> clear all,close all,clc;
> mFile='test.m'
> opts.outputDir = fullfile('.');
> opts.catchError=true
> [MLINTinfo]=mlint(mFile)
> publish(mFile, opts);
> checkErrors=lasterror;
> message = checkErrors.message
> if(~isempty(message))
> fprintf('\nThere is an ERROR!\n');
> end
>
> 3) evaluateTest() produces following output:
>
> mFile =
> test.m
> opts =
> outputDir: '.'
> catchError: 1
> MLINTinfo =
> 0x0 struct array with fields:
> message
> line
> column
> message =
> Error using ==> dbstop
> You can not set a breakpoint past the start of the last
> expression in the file.
>
> There is an ERROR!
>
>
> Best regards,
> Martin
>

This all seems very mysterious. Please contact technical support to
help solve this:

http://www.mathworks.com/support/contact_us/index.html

--
Loren
http://blogs.mathworks.com/loren

Subject: "Error using ==> dbstop"

From: Matthew Simoneau

Date: 29 Jun, 2009 20:11:01

Message: 9 of 17

Publishing uses conditional breakpoints to instrument the file being published. That's where these DBSTOP messages are coming from. I don't know why you're seeing this error, though. What version of MATLAB are you running?

Subject: "Error using ==> dbstop"

From: us

Date: 29 Jun, 2009 20:31:01

Message: 10 of 17

"Matthew Simoneau" <matthew@mathworks.com> wrote in message <h2b74l$n7f$1@fred.mathworks.com>...
> Publishing uses conditional breakpoints to instrument the file being published. That's where these DBSTOP messages are coming from. I don't know why you're seeing this error, though. What version of MATLAB are you running?

as the OP said:
> Hi us,
> thank you for your fast reply.
> - MLINT does not find any errors.
> - CATCHERROR=true
> - I use MATLAB 7.8.0 (R2009a) % <- the version info

please note that the modified code i submitted (apparently) works without errors...
however, if the code is modified to

function r=etest()
     mFile='test.m';
     opts.outputDir='.';
     opts.catchError=true;
     lasterror('reset');
try
     publish(mFile,opts);
catch msg
     error(msg.message);
end
     r=lasterror;
end

% and run as
     r=etest;
% it still does NOT error out - but LASTERROR is set (?!), and the info is

     [{r.stack.line}',{r.stack.name}.',{r.stack.file}.']
%{
% note: nice formatting is off (see in ori view)...
274 findLandingLine codetools\private\evalmxdom.m
 98 setConditionalBreakpoints codetools\private\evalmxdom.m
 48 instrumentAndRun codetools\private\evalmxdom.m
 19 evalmxdom codetools\private\evalmxdom.m
149 publish codetools\publish.m
  7 etest etest.m
%}

us

Subject: "Error using ==> dbstop"

From: us

Date: 29 Jun, 2009 21:09:01

Message: 11 of 17

"us "
> 274 findLandingLine codetools\private\evalmxdom.m

now, if we look at this line (r2009a), we see

function landingLine = findLandingLine(file,targetLine)
% Probe to see where the breakpoint wants to land.
% Precondition: this file has no existing breakpoints.
try
    dbstop(file,num2str(targetLine))
catch %#ok<CTCH>
    % This errors if there aren't any executible lines left or if there is
    % any sort of parse error.
end

which, in turn, is called twice from
    iStartLine = findLandingLine(file, cellBoundaries(iCell, 1));
    iEndLine = findLandingLine(file, cellBoundaries(iCell, 2) + 1); % <- 2nd call

in the OP's case, TARGETLINE is 5 (see OP's TEST.M) and, therefore, the error is caught at the second call to FINDLANDINGLINE with TARGETLINE = 6 and consequently LASTERROR is assigned to

     lasterr
%{
     Error using ==> dbstop
     You can not set a breakpoint past the start of the last
     expression in the file.
%}

my guess: since this try/catch block is a mere lazy construct (for not having to check the validity of the line number), the LASTERROR should be reset (to the previous value, if any) to not cause such troubles...

just a thought
us

Subject: "Error using ==> dbstop"

From: Matthew Simoneau

Date: 29 Jun, 2009 21:26:42

Message: 12 of 17

I see what is going on here. Breakpoints can only go on certain lines in a file, and it's tough to figure out which ones in advance. When instrumenting the file for publishing, PUBLISH just tries to put them where it wants and catches the occasional errors. The reason this is changing the state of LASTERROR is because the CATCH isn't requesting the exception as a variable. To fix this, I just need to change the two lines in matlab/codetools/private/evalmxdom.m from just "catch" to "catch theError". Using this syntax will prevent it from changing the state of LASTERROR and your code should work fine.

Subject: "Error using ==> dbstop"

From: us

Date: 29 Jun, 2009 21:43:01

Message: 13 of 17

"Matthew Simoneau" <matthew@mathworks.com> wrote in message <h2bbii$j2h$1@fred.mathworks.com>...
> I see what is going on here. Breakpoints can only go on certain lines in a file, and it's tough to figure out which ones in advance. When instrumenting the file for publishing, PUBLISH just tries to put them where it wants and catches the occasional errors. The reason this is changing the state of LASTERROR is because the CATCH isn't requesting the exception as a variable. To fix this, I just need to change the two lines in matlab/codetools/private/evalmxdom.m from just "catch" to "catch theError". Using this syntax will prevent it from changing the state of LASTERROR and your code should work fine.

good, problem solved through careful analysis by CSSMers...

us

Subject: "Error using ==> dbstop"

From: Martin

Date: 30 Jun, 2009 13:41:02

Message: 14 of 17

Great! I will test this tomorrow!
I helped myself out by using the publish function of R2007. But changing the evalmxdom in R2009a will be much nicer ;-)
Thanks a lot, us & Matthew!

Best regards,

Martin

Subject: "Error using ==> dbstop"

From: Martin

Date: 2 Jul, 2009 06:33:01

Message: 15 of 17

"Matthew Simoneau" <matthew@mathworks.com> wrote in message <h2bbii$j2h$1@fred.mathworks.com>...
> To fix this, I just need to change the two lines in matlab/codetools/private/evalmxdom.m from just "catch" to "catch theError". Using this syntax will prevent it from changing the state of LASTERROR and your code should work fine.

Hi Matthew,
I changed the code in evalmxdom to "catch theError" and the dbstop error does not occur in lasterror anymore. However, if my testfunction has a real error (e.g. Index exceeds matrix dimensions) it will not be displayed!

e.g.
function test()
a=1;
a(3) %Error
end

function evaluateTest()
lasterror('reset');
opts.outputDir = fullfile('.');
opts.catchError=true;
publish('test.m', opts);
checkErrors=lasterror
end

running the two programs with "try/catch" in evalmxdom will lead to following command line output:

Index exceeds matrix dimensions.
Error in ==> test at 4
a(3)
checkErrors =
       message: [1x102 char]
    identifier: 'MATLAB:lineBeyondFileEnd'
         stack: [6x1 struct]

running the programs with "try/catch theError" in evalmxdom will lead to:
Index exceeds matrix dimensions.
Error in ==> test at 4
a(3)
checkErrors =
       message: ''
    identifier: ''
         stack: [0x1 struct]

I want to store the last real error in the variable "checkErrors", because I then want to generate an report overview for all checked files (something like that:)

-> test.m
     Error in ==> test at 4
    Index exceeds matrix dimensions.
-> test2.m
     ok
-> ...

Is there a possibility to access all errors that have occured (not only the last error)? Then I can search for ~MATLAB:lineBeyondFileEnd errors in this struct.

Best regards,

Martin

Subject: "Error using ==> dbstop"

From: us

Date: 2 Jul, 2009 10:28:53

Message: 16 of 17

"Martin "
> I changed the code in evalmxdom to "catch theError" and the dbstop error does not occur in lasterror anymore. However, if my testfunction has a real error (e.g. Index exceeds matrix dimensions) it will not be displayed!

because things are a bit more complicated...
as i said in my 2nd reply
...the LASTERROR should be reset (to the previous value, if any) to not cause such troubles...

1) using the
     catch theError
   keeps the LASTERROR clean...
2) BUT: m-file errors caught during runtime are NOT put into LASTERR but rather
   LASTE (function instrumentAndRun, line #66)
evalstr = [ ...
    'feature(''hotlinks'',0);' ret ...
    'try' ret ...
    'evalin(''base'',getappdata(0,''' tempVar '''));' ret ...
    endCondition ';' ret ...
    'catch laste, end']; % <- LASTE
3) therefore, to 'reset' LASTERR to the previous value, could do this (nasty) bit
   below line #27
    if options.catchError
        disp(formatError(laste,true)) % <- #27
warning('off','MATLAB:structOnObject'); % <- LASTE: MException obj
lasterror(struct(laste)); %#ok
warning('on','MATLAB:structOnObject');
        beep
    else
        rethrow(laste)
    end

note again: this kludge is necessary due to the fact that the legacy function LASTERR is not an MException obj; nowadays's programs should rely on these objs only...

just a thought...
us

Subject: "Error using ==> dbstop"

From: Martin

Date: 2 Jul, 2009 13:32:01

Message: 17 of 17

> 3) therefore, to 'reset' LASTERR to the previous value, could do this (nasty) bit
> below line #27
> if options.catchError
> disp(formatError(laste,true)) % <- #27
> warning('off','MATLAB:structOnObject'); % <- LASTE: MException obj
> lasterror(struct(laste)); %#ok
> warning('on','MATLAB:structOnObject');

This works!
Thank's a lot!

Best regards,

Martin

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
g561778 Matthew Simoneau 29 Jun, 2009 17:26:42
breakpoints Matthew Simoneau 29 Jun, 2009 16:14:09
error Matthew Simoneau 29 Jun, 2009 16:14:09
publish Matthew Simoneau 29 Jun, 2009 16:14:09
catch us 29 Jun, 2009 07:39:04
publish us 29 Jun, 2009 07:39:04
try us 29 Jun, 2009 07:39:04
code us 29 Jun, 2009 07:39:03
dbstop Martin 25 Jun, 2009 09:59:13
set breakpoints Martin 25 Jun, 2009 09:59:13
compile Martin 25 Jun, 2009 09:59:13
error message Martin 25 Jun, 2009 09:59:13
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com