throw?

15 views
Skip to first unread message

viscomjim

unread,
Dec 31, 2013, 1:10:35 PM12/31/13
to solde...@googlegroups.com
Hi,

I was looking at sample code uart sniffer….

160 IF TXT < 0 THEN THROW TXT

I looked in the reference manual and can't decipher what "throw" does.

Can you help?

Thanks

Jim

CoreBASIC Wizard

unread,
Jan 1, 2014, 5:10:56 AM1/1/14
to solde...@googlegroups.com

THROW is something that will throw an exception. The run-time errors that a running CoreBASIC program can throw (and be caught using TRY) are usually generated internally (e.g. subscript out of range). Each CoreBASiC error is assigned a specific number and the REPORT() function will turn that error number into a string. And, in fact, many device errors are handled the same way, with CoreBASIC throwing low-level device errors direct from the Platform layer. 

You can do the same. If you get a status code back from a function, you can use THROW to turn it into an exception and, if it's not caught, then it terminates the program with a runtime error, the error that THROW threw. But you could equally THROW -999 and see what that does at the command line. -999 is an unknown code, i.e. there is nothing that can turn it into a human-readable description as the kernel doesn't know what it is. 

THROW is there for the moment; but it's intended that the CoreBASIC exception handling mechanism is extended to make TRY and THROW more convenient. As this is not fully written yet, THROW remains undocumented.

Reply all
Reply to author
Forward
0 new messages