mirror of
https://github.com/nineties/planckforth
synced 2025-01-14 08:01:27 +01:00
Add add-error and exception
This commit is contained in:
parent
94a2d829c9
commit
b6967eba48
1 changed files with 35 additions and 0 deletions
35
bootstrap.fs
35
bootstrap.fs
|
@ -1160,3 +1160,38 @@ char 0 char B - constant string-overflow-error \ -18
|
||||||
type
|
type
|
||||||
then
|
then
|
||||||
; immediate
|
; immediate
|
||||||
|
|
||||||
|
( === Error Code and Messages === )
|
||||||
|
|
||||||
|
\ Single linked list of error code and messages.
|
||||||
|
\ Thre structure of each entry:
|
||||||
|
\ | link | code | len | message ... |
|
||||||
|
variable error-list
|
||||||
|
0 error-list !
|
||||||
|
|
||||||
|
: add-error ( n c-addr u -- )
|
||||||
|
error-list here
|
||||||
|
over @ , \ fill link
|
||||||
|
swap ! \ update error-list
|
||||||
|
rot , \ fill error-code
|
||||||
|
dup , \ fill length
|
||||||
|
cmove, \ fill message
|
||||||
|
align
|
||||||
|
;
|
||||||
|
|
||||||
|
decimal
|
||||||
|
|
||||||
|
s" -1" >number drop constant aborted-error
|
||||||
|
|
||||||
|
aborted-error s" Aborted" add-error
|
||||||
|
string-overflow-error s" Too long string literal" add-error
|
||||||
|
|
||||||
|
variable next-user-error
|
||||||
|
s" -256" >number drop next-user-error !
|
||||||
|
|
||||||
|
\ Create new user defined error and returns error code.
|
||||||
|
: exception ( c-addr u -- n )
|
||||||
|
next-user-error @ -rot add-error
|
||||||
|
next-user-error @
|
||||||
|
1 next-user-error -!
|
||||||
|
;
|
||||||
|
|
Loading…
Reference in a new issue