Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 12:24 05 May 2024 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 GOTO nnn

Author Message
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 11:57pm 05 Jul 2017
Copy link to clipboard 
Print this post

  Geoffg said  
<snip> there is no ON ERROR GOTO linenumber statement.


Hello Geoff

Are we ever likely to get it?

Currently MMBasic doesn't have error trapping only error mitigation.

The following code attempts determine which MM it is running on by executing commands that will cause errors on certain models (there are other ways to do this, it is just an illustration)


DIM INTEGER CPUfg

' check 44 pin
IF CPUfg=0 THEN
ON ERROR SKIP 3 ' was hoping to skip 3 statements if an error occurred
SETPIN 42, DIN
SETPIN 42 OFF
CPUfg=44
END IF

' check 28 pin
IF CPUfg=0 THEN
ON ERROR SKIP 3
SETPIN 26,DIN
SETPIN 26 OFF
CPUfg=28
END IF

PRINT CPUfg


Ideally, if the first SETPIN in each IF/ENDIF fails, it would effectively jump to the end of the conditional but this method always fails because the SKIP still executes the commands, but CPUfg=44 always executes so it reports 44 - even on a 28 pin chip.

At the least, if ON ERROR SKIP <n> jumped forwards the specified number of statements then we could assert some control on the flow.

ON ERROR GOTO still gives better control because you need to be aware of the number of statements - adding statements inside the SKIP would break things (potentially).
 
Lightrock
Newbie

Joined: 19/05/2014
Location: Australia
Posts: 26
Posted: 12:21am 06 Jul 2017
Copy link to clipboard 
Print this post

The CFUNCTION CPUType in the official release documentation identifies six known Micromite types.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9066
Posted: 01:57am 06 Jul 2017
Copy link to clipboard 
Print this post

Back in the 1980's when I use Atari Basic, that BASIC did have the TRAP command, and it was very useful indeed for handling errors within the running code.

You would set the trap before a certain section of code, such as TRAP 1050, which would then loop directly to line 1050 if there was any error encountered, and that routine could examine the error register, and decide what to do next.

We do have error trapping for the SD card on the MM, but general trapping would be nice to have. I expect that it is more difficult then you think to add to MMBASIC, or it probably would have made it in there by now.

Geoff?

Peter?
Smoke makes things work. When the smoke gets out, it stops!
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2290
Posted: 02:04am 06 Jul 2017
Copy link to clipboard 
Print this post

the following should accomplish what you want:

On error skip
SetPin 42, DOUT
mm44flag = (MM.Errno=0)



cheers,
rob :-)
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 02:28am 06 Jul 2017
Copy link to clipboard 
Print this post

Lightrock, robert.rozee thanks for the input guys, the code was to illustrate the problem rather than a plea for help - those will come later nice to note MM.ErrNo gets set even if the line is skipped - that could go someway towards the desired TRAPping of errors.

Grogster, it sounds like TRAP did the same as ON ERROR GOTO. It would be nice to have more control over errors but I am thinking I need to remember these are micro-controllers and manage my expectations a bit - writing bug free code would be a plus

cheers
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:35am 06 Jul 2017
Copy link to clipboard 
Print this post

Back in the days when we had ON ERROR RESUME NEXT and ON ERROR GOTO i always preferred the ON ERROR RESUME NEXT (ON ERROR SKIP in MMBasic).
The reason is that you have more control where to resume execution after the error is handled.
Especially when code is run within a DO/LOOP, SELECT CASE or IF statement.


Microblocks. Build with logic.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024