[REBOL] Re: print-error or form-error in system ?
From: tim:johnsons-web at: 13-Nov-2002 8:19
Hmmm! The attachment didn't take, so I'll imbed the files
here... must have coffee before doing complicated things.
;----------------------------------------------------------
rebol[]
cat: :rejoin
print-error: func[ error [object!] /at location /local arg1 arg2 arg3 message out user-raised][
print "<pre>"
either at[
print cat ["==>ERROR in " location ":"]
][ print "==>ERROR:" ]
;;; print mold error
out: make string! 100
set [arg1 arg2 arg3][error/arg1 error/arg2 error/arg3]
if string? arg1[
if (find arg1 "[RAISED]") = arg1[
arg1: chomp/left arg1 "[RAISED]"
user-raised: true
]
]
message: get in get in system/error error/type error/id
if block? message [bind message 'arg1]
append out " "
append out reform reduce message
if all[error/near not user-raised][append out cat[newline " near:^/ " mold error/near
] ]
if all[error/where not user-raised][append out cat[newline " where:^/ " mold error/where]
]
print out
]
chomp: func[str[string!] sub-str[string!] /right /left /first /last /all
/local found sub-len the-chomp][
sub-len: length? sub-str
the-chomp: [remove/part found sub-len]
if left[if (found: find str sub-str) = str[do the-chomp] return str]
if right[
if found: find/tail/last str sub-str[
if empty? found[
found: find/last str sub-str
do the-chomp ] ] return str ]
if first[ if found: find str sub-str[do the-chomp] return str ]
if last[ if found: find/last str sub-str[do the-chomp] return str ]
if all[ while[found: find str sub-str][ do the-chomp ] return str ]
raise["function 'chomp must have one refinement of /right /left /first /last /all"]
]
; raise an error, adds a tag to identify it as a error string only
raise: func[message[block!]][ make error! join "[RAISED]" cat message ];end func
;----------------------------------------------------------
; example "try/catch" construct
application: [; execution block
Print "THIS IS THE EXECUTION BLOCK"
]
;#########################################################################
except: [print-error disarm err ]
if error? set/any 'err try application except
;----------------------------------------------------------
I hope this is of some help.
Tim Johnson <[tim--johnsons-web--com]> [021113 07:42]:
> Hi Anton:
> Let me know if this works for you....
> -tim-
> * Anton <[anton--lexicon--net]> [021112 23:27]:
> > Hi I am looking for a function just as Volker wrote
> > about last year.
> > Has anyone noticed if there is such a function
> > lying around in the system somewhere?
> > I think it must exist somewhere, I just haven't found it.
> >
> > Anton.
> >
> > Volker wrote last year on 21 December 2001:
> > -------------------------
> >
> > RE: [REBOL] Coerting Errors to a string?
> > (original by Bo somewhere, called print-error. forgot if i changed
> > something.)
> >
> > form-error: func [
> > error [object!]
> > /local arg1 arg2 arg3 message out
> > ] [
> > out: make string! 100
> > set [arg1 arg2 arg3] [error/arg1 error/arg2 error/arg3]
> > message: get in get in system/error error/type error/id
> > if block? message [bind message 'arg1]
> > append out reform reduce message
> > append out reform ["^/Near:" mold error/near]
> > append out reform ["^/Where:" mold get in error 'where]
> > ]
> >
> > use with [print form-error disarm error]
> >
> > -Volker
> > -------------------------
> >
> > --
> > To unsubscribe from this list, please send an email to
> > [rebol-request--rebol--com] with "unsubscribe" in the
> > subject, without the quotes.
>
> --
> Tim Johnson <[tim--johnsons-web--com]>
> http://www.alaska-internet-solutions.com
> http://www.johnsons-web.com
>
> -- Attached file included as plaintext by Listar --
>
> rebol[]
> cat: :rejoin
> print-error: func[ error [object!] /at location /local arg1 arg2 arg3 message out user-raised][
> print "<pre>"
> either at[
> print cat ["==>ERROR in " location ":"]
> ][ print "==>ERROR:" ]
> ;;; print mold error
> out: make string! 100
> set [arg1 arg2 arg3][error/arg1 error/arg2 error/arg3]
> if string? arg1[
> if (find arg1 "[RAISED]") = arg1[
> arg1: chomp/left arg1 "[RAISED]"
> user-raised: true
> ]
> ]
> message: get in get in system/error error/type error/id
> if block? message [bind message 'arg1]
> append out " "
> append out reform reduce message
> if all[error/near not user-raised][append out cat[newline " near:^/ " mold error/near
] ]
> if all[error/where not user-raised][append out cat[newline " where:^/ " mold error/where]
]
> print out
> ]
> chomp: func[str[string!] sub-str[string!] /right /left /first /last /all
> /local found sub-len the-chomp][
> sub-len: length? sub-str
> the-chomp: [remove/part found sub-len]
> if left[if (found: find str sub-str) = str[do the-chomp] return str]
> if right[
> if found: find/tail/last str sub-str[
> if empty? found[
> found: find/last str sub-str
> do the-chomp ] ] return str ]
> if first[ if found: find str sub-str[do the-chomp] return str ]
> if last[ if found: find/last str sub-str[do the-chomp] return str ]
> if all[ while[found: find str sub-str][ do the-chomp ] return str ]
> raise["function 'chomp must have one refinement of /right /left /first /last /all"]
> ]
> ; raise an error, adds a tag to identify it as a error string only
> raise: func[message[block!]][ make error! join "[RAISED]" cat message ];end func
> ; example "try/catch" construct
> application: [; execution block
> Print "THIS IS THE EXECUTION BLOCK"
> ]
> ;#########################################################################
> except: [print-error disarm err ]
> if error? set/any 'err try application except
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
http://www.johnsons-web.com