RE: [REBOL] Re: Coerting Errors to a string?

use:
  if error? lv-err: try [Print "AAA" 'ok] [Print "Error"]

if there is no error, try works like do, returning the last value.
with 
  if error? lv-err try [1 / 2] [Print "Error"] ; works 
you return a number, but with
  if error? lv-err try [Print "AAA"] [Print "Error"] ; does not work
you return unset! (the result of a 'print)
so return something, i suggest 'ok here, anything goes.
or use
  if error? set/any 'lv-err try [Print "AAA"] [Print "Error"]  
which works ok with unset! too.

-Volker
  


[EMAIL PROTECTED] wrote:
> 
> Thanks Volker,
> 
> I will use this in my error handling
> 
> The next question is am I handling my errors correctly?
> For Example
> 
> if error? lv-err: try [1 / 0] [Print "Error"] ; works
> if error? lv-err try [1 / 2] [Print "Error"] ; works
> 
> However
> if error? lv-err try [Print "AAA"] [Print "Error"] ; does not work
> gives
> 
> AAA
> ** Script Error: lv-err needs a value
> ** Near: if error? lv-err: try [Print "AAA"]
>
> Cheers Phil
> 
> === Original Message ===
> 
> 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
> 
> [EMAIL PROTECTED] wrote:
> > 
> > Hi Guys,
> > 
> > Given that my program recieves an error I disarm it, and I have an error object, 
>for  example
> > 
> > err: disarm try [a: 1 / 0]
> > 
> > probe err
> > 
> > make object! [
> >     code: 400
> >     type: 'math
> >     id: 'zero-divide
> >     arg1: none
> >     arg2: none
> >     arg3: none
> >     near: [a: 1 / 0]
> >     where: none
> > ]
> > 
> > How do I convert it to a nicely formatted readable string ?
> > 
> > >> err
> > ** Math Error: Attempt to divide by zero
> > ** Near: a: 1 / 0
> > 
> > 
> > 
> > -- 
> > To unsubscribe from this list, please send an email to
> > [EMAIL PROTECTED] with "unsubscribe" in the 
> > subject, without the quotes.
> > 
> -- 
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the 
> subject, without the quotes.
> 
> 
> -- 
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the 
> subject, without the quotes.
> 
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to