Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
better error trapping?
#3
(01-06-2023, 08:07 PM)Spriggsy Wrote: You can emulate the try/catch by setting up a block with an "on error goto". A try catch would be quite nice, though. Even if it means it will be _TRY _CATCH..... blegh.... Thank God for $NOPREFIX.

Something I just thought about, though, would be that you'd only be catching exceptions that QB64 runtime throws. It wouldn't be useful for someone like me, who uses external libraries and wouldn't have the ability to catch exceptions from the libraries in this way. I'd have to stick to if statements and GetLastError instead.

The big problem with "on error goto" is, well, firstly, it uses GOTO! And even worse is that in QB64/PE, the compiler won't let the target of the GOTO be inside of a function or sub, or inbetween routines, it has to appear before any functions/subs. So now we're jumping somewhere outside the function - convoluted. In VB6/VBA (but not VBSCRIPT!) the error handling code can at least be put inside the routine itself. 

I prefer ON ERROR RESUME NEXT, and then testing if err.number <> 0 then [handle error and err.clear].  

But an inline try/catch is just cleaner. I don't know about error handling for external APIs, how do .NET, Java, JavaScript, or Python implement it? It's been a loooong time since I did .NET, but I do remember the error object was pretty rich, it even had stack trace! I don't recall anything about what details bubbled up from an exception originating from an external dependency, but I would think if the QB64PE runtime calls an external library, it's up to the library to catch exceptions and to send back some kind of meaningful error code or message? Because otherwise wouldn't it just freeze up and time out?
Reply


Messages In This Thread
better error trapping? - by madscijr - 01-06-2023, 06:57 PM
RE: better error trapping? - by SpriggsySpriggs - 01-06-2023, 08:07 PM
RE: better error trapping? - by madscijr - 01-06-2023, 09:29 PM
RE: better error trapping? - by SpriggsySpriggs - 01-06-2023, 09:42 PM
RE: better error trapping? - by madscijr - 01-07-2023, 03:34 AM
RE: better error trapping? - by mnrvovrfc - 01-06-2023, 11:22 PM
RE: better error trapping? - by mnrvovrfc - 01-07-2023, 03:38 AM
RE: better error trapping? - by madscijr - 01-08-2023, 03:59 AM
RE: better error trapping? - by aurel - 01-08-2023, 09:11 AM
RE: better error trapping? - by mnrvovrfc - 01-08-2023, 09:50 AM
RE: better error trapping? - by Fifi - 01-09-2023, 11:25 AM
RE: better error trapping? - by aurel - 01-08-2023, 04:09 PM
RE: better error trapping? - by bplus - 01-08-2023, 04:19 PM
RE: better error trapping? - by aurel - 01-08-2023, 05:18 PM
RE: better error trapping? - by bplus - 01-08-2023, 06:29 PM
RE: better error trapping? - by DSMan195276 - 01-08-2023, 06:33 PM



Users browsing this thread: 5 Guest(s)