Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:01 01 Aug 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 : ON ERROR SKIP and Interrupts

     Page 1 of 3    
Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 04:21am 09 Apr 2022
Copy link to clipboard 
Print this post

Well, this seems like an interesting anomaly.

settick 25,TestMe,1
do
  on error skip
  a = 2 / 0
loop

sub TestMe
  i = i + 1
end sub

Turn off the timer interrupt and it works fine. (I'm testing on a CMM2.)
It's pretty clear why it fails, but how should it behave?
Visit Vegipete's *Mite Library for cool programs.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 05:13am 09 Apr 2022
Copy link to clipboard 
Print this post

@Vegipete

Other way around I think mate   , with settick enabled, I get the divide by zero message, with settick disabled, it just goes into nowhere land.

I think this would be expected as the on error skip is jumping over the loop command into ??? I think the settick interrupt sub is effectively the next instruction after the loop statement and this is where the error condition jumps in?

If you put a line in after the a = 2/0 like print "hi" or whatever, that will be evaluated after the error line is skipped over and the loop will then also be evaluated whether settick is enabled or not.
Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 06:28am 09 Apr 2022
Copy link to clipboard 
Print this post

  panky said  with settick enabled, I get the divide by zero message, with settick disabled, it just goes into nowhere land.
Exactly.

The ON ERROR SKIP statement should prevent the divide by zero from ever reporting an error. However, because of the interrupt, sometimes (often?) the divide by zero line is NOT the next statement after the ON ERROR.

Print i at the prompt after the error - the value can vary depending on how many times the ISR fired before the error happens.

The issue is, because of interrupts, you can't determine which statement/s might be skipped by the ON ERROR SKIP command.
Visit Vegipete's *Mite Library for cool programs.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 08:29am 09 Apr 2022
Copy link to clipboard 
Print this post

Oh horrors. That really reduces the value of ON ERROR SKIP!

Could it be a change somehow introduced accidentally?

Is there a workaround (other than turning off interrupts)?

I suppose MMBasic could be changed not to look for interrupts until after the next statement...

John
Edited 2022-04-09 18:30 by JohnS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 08:38am 09 Apr 2022
Copy link to clipboard 
Print this post

Perhaps the setting of ON ERROR needs to be ignored within interrupts, or taking it a step further there should be separate ON ERROR states for the normal path and the interrupt path.

Fun!!!

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 08:40am 09 Apr 2022
Copy link to clipboard 
Print this post

What's up with turning off interrupts during an ON ERROR SKIP? They won't be off long.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 09:21am 09 Apr 2022
Copy link to clipboard 
Print this post

I'm probably in a minority of one on this but personally I would remove ON ERROR from the language entirely. I've never used it in "real" code and never would. IMHO is is just a mechanism for hiding programming that doesn't properly cater for the various conditions that may arise.
I'm pretty sure all variants of MMbasic will display the symptoms found by vegipete and I certainly won't be making changes to the firmware to get round them.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 09:42am 09 Apr 2022
Copy link to clipboard 
Print this post

  matherp said  I'm probably in a minority of one on this but personally I would remove ON ERROR from the language entirely.


Please don't do that, it's vital to allow unit-testing of error conditions.

  matherp said  I've never used it in "real" code and never would. IMHO is is just a mechanism for hiding programming that doesn't properly cater for the various conditions that may arise.


I think there are File I/O error conditions for which MMBasic doesn't provide commands/functions to detect before they report an error.

Best wishes,

Tom
Edited 2022-04-09 20:34 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 09:42am 09 Apr 2022
Copy link to clipboard 
Print this post

Deleted duplicate post.
Edited 2022-04-09 19:43 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 03:39pm 09 Apr 2022
Copy link to clipboard 
Print this post

This came about because I was blitting something onto the screen, except that sometimes the image wasn't visible. Instead of testing for visibility, I used an ON ERROR to skip off screen drawing. Simple enough. Most other drawing commands happily do nothing if acting off-screen, but not BLIT.

This lazy (Matherp NOT-approved ;) method started to fail once I added interrupts.

=====================
If there _were_ to be a solution, JohnS and Mixtel90's idea seems most logical: after an ON ERROR SKIP [n] statement, interrupts would not be serviced for 1 (or n) interrupts. I'm not aware of a method of stopping (and restarting) all possible interrupts in MMBasic. This change to ON ERROR behavior would add a potentially useful ability to stop interrupts while a set of instructions that must be atomic executes.
Edited 2022-04-10 01:41 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 442
Posted: 04:17pm 09 Apr 2022
Copy link to clipboard 
Print this post

  matherp said  I'm probably in a minority of one on this but personally I would remove ON ERROR from the language entirely. I've never used it in "real" code and never would. IMHO is is just a mechanism for hiding programming that doesn't properly cater for the various conditions that may arise.
I'm pretty sure all variants of MMbasic will display the symptoms found by vegipete and I certainly won't be making changes to the firmware to get round them.


It can hide sloppy code but it can also recover from user and hardware errors. Suppose you ask for a filename to open and the user types in a filename that doesn't exist? Do you really want the program to exit with an error message or do you want to give the user another chance to enter the filename correctly? How about a hardware error while reading or writing a file? No commercial program should ever exit unexpectedly. There should be no way out of the program other than the graceful exit designed by the programmer. I worked in IT for over 40 years and I'd have been fired if my users ever had the program dump them to a DOS or bash prompt.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 04:39pm 09 Apr 2022
Copy link to clipboard 
Print this post

Agreed, it has its place. :) When messing with hardware though, you should always *expect* a failure and be pleasantly surprised if it works ok (unless the programme is something pretty trivial). If that means disabling interrupts while you activate a drive or something then so be it. There could be anything happening - cat asleep on a drive causing it to overheat, data fallen off the floppy (along with the magic rust powder), user's little daughter "posted" things into the drive slot (don't you dare laugh!) - anything.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 06:52pm 09 Apr 2022
Copy link to clipboard 
Print this post

  thwill said  ... I think there are File I/O error conditions for which MMBasic doesn't provide commands/functions to detect before they report an error.
...

+1
causality ≠ correlation ≠ coincidence
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 07:03pm 09 Apr 2022
Copy link to clipboard 
Print this post

"File FUBAR - Jam on Disk"

:(
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 09:26pm 09 Apr 2022
Copy link to clipboard 
Print this post

  Quote  I think there are File I/O error conditions for which MMBasic doesn't provide commands/functions to detect before they report an error.


Example of something that can't be coded round?
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 09:51pm 09 Apr 2022
Copy link to clipboard 
Print this post

  matherp said  
  Quote  I think there are File I/O error conditions for which MMBasic doesn't provide commands/functions to detect before they report an error.

Example of something that can't be coded round?


I really don't want to play this game since we both know you aren't actually going to remove ON ERROR SKIP, but at a guess, missing SD card, full SD card, unreadable SD card, unwritable SD card ?

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 10:13pm 09 Apr 2022
Copy link to clipboard 
Print this post

Plus on performance grounds isn't an ON ERROR SKIP much cheaper than what at a minimum would be an IF statement and a variable lookup?

I'm really surprised this hasn't come up before (maybe it has?), I guess you just have to be really unlucky for an interrupt to fire between an ON ERROR SKIP and a statement that can and in a given instance does throw an error.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 11:50pm 09 Apr 2022
Copy link to clipboard 
Print this post

I use it to test whether a file exists or not in Geoff's MMBasic for Windows.

function file_exist(fe$, fn)
on error skip 1
open fe$ for input as #fn
if mm.errno = 0 then close #fn
file_exist = mm.errno = 0
end function

Is there a better way?

Bill
Keep safe. Live long and prosper.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 02:49am 10 Apr 2022
Copy link to clipboard 
Print this post

  Turbo46 said  
Is there a better way?

Bill

Different, not "better"
file$ = "testing.bas"
IF MM.INFO$(SDCARD) = "Ready" THEN
OPEN "testit.txt" FOR OUTPUT AS #1
CLOSE #1
PRINT MM.INFO$(FILESIZE file$)     ' existing file
PRINT MM.INFO$(FILESIZE "test")    'existing directory
PRINT MM.INFO$(FILESIZE "wrong.nam") 'nonexisting file
'junk$ = dir$("",file)             'without this, zero bytes on pico files give error
PRINT MM.INFO$(FILESIZE "testit.txt")
ELSE
PRINT "Put it back!!!"
ENDIF


On the pico, I get an error for zero byte files unless you do a DIR$() first. !!A BUG!!
On MMB4W, there is no SD card so that line gives an error as expected.
Filesize returns filesize (including zero) if present, -2 if directory or -1 if not found.

Edit: Sorry Bill, I just noticed that you are using the original MMBasic.exe, not MMB4W so most of my commands are missing.

Jim
Edited 2022-04-10 13:12 by TassyJim
VK7JH
MMedit
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2442
Posted: 04:25am 10 Apr 2022
Copy link to clipboard 
Print this post

  matherp said  I'm probably in a minority of one on this but personally I would remove ON ERROR from the language entirely. I've never used it in "real" code and never would. IMHO is is just a mechanism for hiding programming that doesn't properly cater for the various conditions that may arise.
I'm pretty sure all variants of MMbasic will display the symptoms found by vegipete and I certainly won't be making changes to the firmware to get round them.


i am inclined to side with Peter on this one, even though i did use ON ERROR in a piece of test code i'd run over every E-28 module built. i also believe i may have been one of the people who pushed for Geoff to include some sort of error catching  

bearing in mind that i am mostly just interested in the MX170 version of mmbasic, used in embedded applications, in general when an error occurs things should stop and tell the operator (or trigger a watchdog event). i would suggest that ON ERROR should be classed alongside TRACE ON|OFF and MEMORY. that is, things used during development but not left in the final production code.


one simple solution: edit the mmbasic manuals to clearly state that ON ERROR may cause unexpected behavior when an interrupt is triggered. with any product, there will always be some 'odd' behaviors that exist, the important thing is that these behaviors are clearly documented  


just my opinion,
rob   :-)
Edited 2022-04-10 14:27 by robert.rozee
 
     Page 1 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025