Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:10 17 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2 - question regarding ON ERROR SKIP

     Page 1 of 2    
Author Message
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 01:23pm 11 Feb 2021
Copy link to clipboard 
Print this post

The manual reads:
  Quote  ON ERROR SKIP [nn]
ON ERROR SKIP will ignore an error in a number of commands (specified by
the number 'nn') executed following this command. 'nn' is optional, the default
if not specified is one. After the number of commands has completed ((with an
error or not)
) the behaviour of MMBasic will revert to ON ERROR ABORT.


So my understanding is that
ON ERROR SKIP
<command 1>
<command 2>


will skip any error in <command 1> but will break on any error in <command 2>.
Is that correct?  Or should it ignore an error in <command 2> if there was no error in <command 1>?

I stumbled upon this with following code for nunchuk test:
option explicit
on error skip
controller nunchuk open 3
if mm.errorno<>0 then
  print "no nunchuk"
else
  print "ok"
endif
controller nunchuk close 3


Even with my nunchuk in port 3 this gives an "no nunchuk" as output - I misspelled mm.errno as mm.errorno!

If I remove the on error skip I get "Error in line 5: MM.ERRORNO is not declared" as expected.

Bjoerg

Edit: Reversed if-condition to make it more clear.
Edited 2021-02-11 23:35 by Schlowski
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 12:55pm 12 Feb 2021
Copy link to clipboard 
Print this post

Nothing?

How about this:

option explicit
on error skip 1
?"Check error handling:"
if mm.errorno<>0 then  
  print "I should never arrive here!"
endif


The result is
Check error handling:
I should never arrive here!


Without "on error skip 1" it reports an error as expected:
Error in line 5: MM.ERRORNO is not declared
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 01:51pm 12 Feb 2021
Copy link to clipboard 
Print this post

  Schlowski said  The manual reads:
  Quote  ON ERROR SKIP [nn]
ON ERROR SKIP will ignore an error in a number of commands (specified by
the number 'nn') executed following this command. 'nn' is optional, the default
if not specified is one. After the number of commands has completed ((with an
error or not)
) the behaviour of MMBasic will revert to ON ERROR ABORT.


So my understanding is that
ON ERROR SKIP
<command 1>
<command 2>


will skip any error in <command 1> but will break on any error in <command 2>.
Is that correct?

Yes.

The wording in the manual is "commands ... executed following this command" and it means just that.

John
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 02:02pm 12 Feb 2021
Copy link to clipboard 
Print this post

Thanks, then my examples indicate a problem with ON ERROR SKIP, right?

Edit:
if I switch the code to
option explicit
on error skip 1
?"Check error handling:"
print mm.errorno

then I get an error at the line "print mm.errorno".

So it really skips error handling for one command and reports the error on the next line.
But then something goes wrong if the next statement is an if instead of a print-command.
Edited 2021-02-13 01:04 by Schlowski
 
erbp
Senior Member

Joined: 03/05/2016
Location: Australia
Posts: 195
Posted: 01:30am 13 Feb 2021
Copy link to clipboard 
Print this post

  Schlowski said  
then I get an error at the line "print mm.errorno".


The problem is you are using the wrong variable name. Check the manual - mm.errorno should be MM.ERRNO.
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 08:48am 13 Feb 2021
Copy link to clipboard 
Print this post

That's clear but with on error skip TWO lines before the faulty if-statement no error is reported and this is a bug in MMBasic.

This reports the error with the misspelled variable name:
option explicit
on error skip 1
?"Check error handling:"
print mm.errorno


This does not report an error:
option explicit
on error skip 1
?"Check error handling:"
if mm.errorno<>0 then  
 print "I should never arrive here!"
endif

Edited 2021-02-13 18:52 by Schlowski
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 09:08am 13 Feb 2021
Copy link to clipboard 
Print this post

It isn't a bug except in your understanding

on error skip n skips the next n lines if the line following has an error

Perhaps the manual needs to be clearer but this is the way every single version of MMBasic has always worked
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 09:21am 13 Feb 2021
Copy link to clipboard 
Print this post

Edit: Nevermind, my fault. So ON ERROR SKIP 1 keeps active until an error occurred, now I got it...
Than everything works as expected, thanks for the clarification!
Edited 2021-02-13 19:23 by Schlowski
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 10:05am 13 Feb 2021
Copy link to clipboard 
Print this post

  Schlowski said  So ON ERROR SKIP 1 keeps active until an error occurred

No, completely wrong.  It is only "active" for the next command.

From the manual:
  Quote  ON ERROR SKIP will ignore an error in a number of commands (specified by the number 'nn') executed following this command.  

It cannot be much clearer than that!

Geoff
Geoff Graham - http://geoffg.net
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 10:27am 13 Feb 2021
Copy link to clipboard 
Print this post

  Schlowski said  This does not report an error:
option explicit
on error skip 1
?"Check error handling:"
if mm.errorno<>0 then  
 print "I should never arrive here!"
endif


Oh. I think that should be an error.

edit: Now I'm confused. I don't see how mm.errorno isn't being picked up as an error because of the option explicit.

John
Edited 2021-02-13 20:32 by JohnS
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 10:37am 13 Feb 2021
Copy link to clipboard 
Print this post

@geoff:
Ok, so please explain what the following code is expected to do:

option explicit
on error skip 1
?"Check error handling:"
if mm.errorno<>0 then  
print "I should never arrive here!"
endif


My understanding is that it should report an error about mm.errorno not declared. But instead it prints "I should never arrive here!"
Edited 2021-02-13 20:42 by Schlowski
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 12:01pm 13 Feb 2021
Copy link to clipboard 
Print this post

You have uncovered a bug in the CMM2 implementation of MMBasic.  At least in V5.06.00 which was what I tested.  It seems that on the CMM2 one extra command is skipped.  So, SKIP 1 will ignore errors in the next two commands, SKIP 2 will ignore errors in three commands, etc.

I will report it to Peter.

Regardless, the manual is correct (except for this miscount).  On the Micromite (V5.05.03) you will get:
> Micromite MKII MMBasic Ver 5.05.03
Copyright 2011-2020 Geoff Graham

> LIST
option explicit
on error skip 1
print "Check error handling:"
if mm.errorno<>0 then
 print "I should never arrive here!"
endif
>
> RUN
Check error handling:
[4] If mm.errorno<>0 Then
Error : MM.ERRORNO is not declared
>

Geoff
Geoff Graham - http://geoffg.net
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 12:25pm 13 Feb 2021
Copy link to clipboard 
Print this post

Thanks Geoff, that was what I expected after reading the manual.

Funny thing is that if you switch
if mm.errorno<>0 then


to
? mm.errorno


MMBasic on the CMM2 throws an error. So it seems to be related to the condition evaluation of the if.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 01:04pm 13 Feb 2021
Copy link to clipboard 
Print this post

Bug is in all versions of MMBasic - could be considered a feature

The expectation is that you only use ON ERROR SKIP when the next line is potentially going to give the error. It then skips the number of subsequent lines specified.

What the code does is start a line count when you execute ON ERROR SKIP and until the line count reduces to zero any lines during the count will not produce an error
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 01:18pm 13 Feb 2021
Copy link to clipboard 
Print this post

That's inconsistent as this throws a runtime error:

prog #1
option explicit
1: on error skip 1
2: ?"Check error handling:"
3: print mm.errorno


But this doesn't:

prog #2
option explicit
1: on error skip 1
2: ?"Check error handling:"
3: if mm.errorno<>0 then  
4:    print "I should never arrive here!"
5: endif


ON ERROR SKIP 1 should ignore any error in line 2, but throw errors in lines 3 and following. So far, so good, that's not difficult to understand.

Prog #1 throws an error on line 3 as expected, but prog #2 ignores the erro in line 3 -> that's a bug and an inconsistency in the behaviour of ON ERROR SKIP.

Btw. my original test was for OPEN CONTROLLER NUNCHUK (see first post), I just misspelled mm.errno and got beside OPTION EXPLICIT no error - this can lead to really nasty and fifficult to spot erros in your code...
Edited 2021-02-13 23:30 by Schlowski
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 01:26pm 13 Feb 2021
Copy link to clipboard 
Print this post

  Quote  That's inconsistent as this throws a runtime error:


No: The print statement decrements the line count and then the invalid variable gives the error. Basically at the moment every line after the ON ERROR command decrements the count, error or not. Code from MM2

           nextstmt = cmdline = p + 1;
           skipspace(cmdline);
           skipelement(nextstmt);
           if(*p && *p != '\'') {                                  // ignore a comment line
               if(setjmp(ErrNext) == 0) {                          // return to the else leg of this if error and OPTION ERROR SKIP/IGNORE is in effect
                   SaveLocalIndex = LocalIndex;                    // save this if we need to cleanup after an error
                   if(*(char*)p >= C_BASETOKEN && *(char*)p - C_BASETOKEN < CommandTableSize - 1 && (commandtbl[*(char*)p - C_BASETOKEN].type & T_CMD)) {
                       cmdtoken = *(char*)p;
                       targ = T_CMD;
                       commandtbl[*(char*)p - C_BASETOKEN].fptr(); // execute the command
                   } else {
                       if(!isnamestart(*p)) error("Invalid character: @", (int)(*p));
                       i = FindSubFun(p, false);                   // it could be a defined command
                       if(i >= 0) {                                // >= 0 means it is a user defined command
                           DefinedSubFun(false, p, i, NULL, NULL, NULL, NULL);
                       }
                       else
                           error("Unknown command");
                   }
               } else {
                   LocalIndex = SaveLocalIndex;                    // restore so that we can clean up any memory leaks
                   ClearTempMemory();
               }
               if(OptionErrorSkip > 0) OptionErrorSkip--;          // if OPTION ERROR SKIP decrement the count - we do not error if it is greater than zero

Edited 2021-02-13 23:27 by matherp
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 01:31pm 13 Feb 2021
Copy link to clipboard 
Print this post

see my edited post above...
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 01:35pm 13 Feb 2021
Copy link to clipboard 
Print this post

As it fails as expected on a Micromite, I'm puzzled why it doesn't fail in the same way on the CMM2.

(E.g. perhaps there is something different about the way IF is handled? E.g. perhaps it's to do with the semi-compile scan / tokenisation or whatever it's called. Etc)

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 02:07pm 13 Feb 2021
Copy link to clipboard 
Print this post

Please download and try b14 should be OK - I hope
 
Schlowski
Newbie

Joined: 26/03/2014
Location: Germany
Posts: 29
Posted: 02:20pm 13 Feb 2021
Copy link to clipboard 
Print this post

Perfect, works, throws an error in both progs.
Thanks matherp!
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025