Author Topic: Auto-changing _ERRORLINE Line?  (Read 3157 times)

0 Members and 1 Guest are viewing this topic.

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Auto-changing _ERRORLINE Line?
« on: November 24, 2019, 02:41:08 pm »
Is this already a thing?  If I use _ERRORLINE in a handler to point to the actual faulty program line, as seen here:
Code: QB64: [Select]
  1. 'This is program line #1
  2. 'This is program line #2
  3. 'This is program line #3
  4.  
  5. ON ERROR GOTO Error_Handler
  6.  
  7. FOR Num = 0 TO 11
  8.     Array(Num) = Num * 10 '       <---- Line that causes "out of range" error ----
  9.  
  10.  
  11. Error_Handler:
  12.  
  13. PRINT "Error on line"; _ERRORLINE

...and then I insert more lines of code, comments, whatever:

Code: QB64: [Select]
  1. 'This is program line #1
  2. 'This is program line #2
  3. 'This is program line #3
  4. 'This is program line #4            <---- Inserted line ----
  5.  
  6. ON ERROR GOTO Error_Handler
  7.  
  8. FOR Num = 0 TO 11
  9.     Array(Num) = Num * 10
  10.  
  11.  
  12. Error_Handler:
  13.  
  14. PRINT "Error on line"; _ERRORLINE

...it seems obvious to me that the 8 on the IF _ERRORLINE line should automatically change to a 9.  Yes?  Of course, yes.  If possible, that is.  I wouldn't know;  I'm just a dummy who manages somehow to write some pretty cool games and such, using my pretty-basic knowledge of BASIC.  Thanks for reading.
« Last Edit: November 24, 2019, 03:29:51 pm by SirCrow »
I may not always finish what I've started....

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Auto-changing _ERRORLINE Line?
« Reply #1 on: November 24, 2019, 04:19:04 pm »
Quote
Code: QB64: [Select]
This is the height of foolishness. Never assume something so definite about line numbers, because they will change at some point; and no, the ide is not going to update random constants for you.

Use multiple error handlers and appropriate application of ON ERROR instead.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Auto-changing _ERRORLINE Line?
« Reply #2 on: November 24, 2019, 06:15:20 pm »
Hi

this code may be better
Code: QB64: [Select]
  1. 'This is program line #1
  2. 'This is program line #2
  3. 'This is program line #3
  4. 'This is program line #4            <---- Inserted line ----
  5.  
  6. ON ERROR GOTO Error_Handler
  7.  
  8. FOR Num = 0 TO 11
  9.     Array(Num) = Num * 10
  10.  
  11.  
  12. Error_Handler:
  13. ' identify the error for type and feedback line of error and code of error
  14. IF ERR = 9 THEN PRINT "at line "; _ERRORLINE; " code "; ERR; "Out of range": BEEP: RESUME NEXT
  15. IF ERR = 53 THEN PRINT "Error on line"; _ERRORLINE; "code "; ERR; "file not found": RESUME NEXT
  16.  
Programming isn't difficult, only it's  consuming time and coffee

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Auto-changing _ERRORLINE Line?
« Reply #3 on: November 24, 2019, 10:26:30 pm »
This is the height of foolishness.

Hahaha!

 I like that, but perhaps writing code that can error in the first place is the "height of foolishness" an thus we are all fools!

But Luke is right, welcome to the realm of "Be A Responsible Programmer!" don't expect somebody(or something) else to do all the work for you.
Granted after becoming radioactive I only have a half-life!

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: Auto-changing _ERRORLINE Line?
« Reply #4 on: November 26, 2019, 07:51:08 pm »
Hahaha!

 I like that, but perhaps writing code that can error in the first place is the "height of foolishness" an thus we are all fools!

But Luke is right, welcome to the realm of "Be A Responsible Programmer!" don't expect somebody(or something) else to do all the work for you.

At least I can say that by the time I consider a program finished (enough), it runs pretty well without even using a handler routine.
For a programmer as sloppy as myself, with very limited skill and poor concentration, this is very impressive indeed. ;-)
I may not always finish what I've started....