Author Topic: ON ERROR THEN  (Read 2789 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
ON ERROR THEN
« on: September 07, 2021, 09:48:44 pm »
Jaze posted a cryptogram program earlier which the code led me to thinking: Why isn’t there an ON ERROR THEN syntax?

We have both version for IF:

IF X THEN…

IF X GOTO…

Why do we have to have:

ON ERROR GOTO crap
GOTO beginning
crap:
PRINT "Error, Line number"
PRINT ERR, _ERRORLINE
END
beginning:


Why isn’t there a simple:

ON ERROR THEN
    PRINT "Error, Line number"
    PRINT ERR, _ERRORLINE
END ON ERROR
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: ON ERROR THEN
« Reply #1 on: September 07, 2021, 11:26:51 pm »
I saw that post, too. My take is this. ON ERROR is best used as...

Code: QB64: [Select]
  1. ON ERROR GOTO errhandler
  2.  
  3.  LOCATE -1, -1
  4. PRINT "This routine is buggy!"
  5.  
  6.  
  7. errhandler:
  8.  

No need to shunt around an error handler with something like "GOTO beginning" when it is used in this fashion. Also, it is an exception of GOTO where the developers made it possible to place the error handler in the main, while allowing ON ERROR GOTO to be placed in subs. The only complaint I had (back in the day) was in multi-modular programming, one had to make an error handler for each module. There was no way to make a universal error handler back then. Nowadays, multi-modular programming is completely unnecessary.

Pete

 
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Jaze

  • Newbie
  • Posts: 86
    • View Profile
Re: ON ERROR THEN
« Reply #2 on: September 08, 2021, 11:20:40 am »
Looking at what was said about me going around the error portion with "GOTO beginning". If I took out the label and the GOTO would the ide simply pass the ERROR label? How exactly should that work?  Btw, didn't know ON ERROR could be used in a SUB, so thanks for that.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: ON ERROR THEN
« Reply #3 on: September 09, 2021, 04:45:58 am »
I agree with Steve.  I hate using ON ERROR GOTO which requires the two labels and code stepping over each other.  A hand-me-down from QB2 (or the original BASIC?).

When the team have come up with the new ON ERROR THEN, could we have it with an ELSE as well:

ON ERROR THEN

    PRINT "Point out to that idiot Qwerkey that he has made yet another stupid error in his code."
    PRINT "Why did we ever let this fool anywhere near QB64?"
    PRINT ERR, _ERRORLINE

    ELSE
   
    ' Carry on with the rest of Qwerkey's amazing Masterwork of efficiently written QB64 code.

END ON ERROR

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: ON ERROR THEN
« Reply #4 on: September 09, 2021, 12:18:05 pm »
Code: QB64: [Select]
  1. Why do we have to have:
  2.  

Dollars to donuts it's for compatibility with old code.

Plus, what a mess it would make of using a THEN for an IF block.
« Last Edit: September 09, 2021, 12:24:43 pm by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: ON ERROR THEN
« Reply #5 on: September 09, 2021, 06:36:46 pm »
Hi brothers and sisters
just some philosophical thoughts about
ON ERROR GOTO  &&  ON ERROR THEN  && ON ERROR THEN......END ON ERROR


1. goal of ON ERROR GOTO is clearly managing the exception to the normal (planned) flow of program so the ELSE is still managed by code 
Code: QB64: [Select]
  1. On Error GoTo NextVideoMode
  2. A = 0
  3. While A < 14
  4.     Screen A
  5.     Line (10, 10)-(100, 100), 14
  6.     Print " Press a key to continue"
  7.     Sleep
  8.     A = A + 1
  9.  
  10.  
  11. NextVideoMode:
  12. A = A + 1
  13. Print " Error: Screen mode = "; A - 1

2. I have seen code with ON ERROR GOTO to manage issues like File not found, VideoMode not avaiable indeed illegal funtion call for a graphic statement , out of DATA, Subscritpt Out of Range. For many of these we have specific _QB64 _Keywords to verify to avoid the error on fly.

3. the GOTO /RESUME / RESUME NEXT(Yeah only QB PDS) is an haitful old fashioned structure. But it works!
Yes I would prefer ON ERROR THEN (one line statement without ELSE or END ON ERROR but just the first primitive IF...THEN) to call directly the sub managing the error, so the code to manage can be used also in a recursive way but to get this I must only put the name of SUB just between ErrorLabel:  and  RESUME
Code: QB64: [Select]
  1. ON ERROR GOTO ThisIsAnError
  2.  
  3. 'program instructions...
  4.  
  5.  
  6. SUB SolveError
  7. ' it makes the right changements
  8.  
  9. ThisIsAnError:
  10.  SolveError
  11.  

Why don't like multiple lines ON ERROR THEN?
Because in a sub you can put as many as statements and controls you want to have.
So we can do that without developing more keywords.

PS just some mine thoughts. Don't mind
Programming isn't difficult, only it's  consuming time and coffee