Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Help me, Obi Reb Kenobi, you're my only hope!

From: carl:cybercraft at: 28-Aug-2002 17:49

Hee - wasted time on this myself today! The problem is that 'print doesn't return a value when 'Fred is expecting one...
>> Fred: print "What's wrong with this?"
What's wrong with this? ** Script Error: Fred needs a value ** Near: Fred: print "What's wrong with this?" and it's not trapped by your error routine as 'Fred is outside the block that's being 'try'ed. Place 'Fred inside it and you'll trap the error...
>> If Error? try [Fred: Print "See?"][Print "Whatever!"]
See? Whatever! It's possible to write a function that'll check for nothing returned, as the any-type! datatype will accept nothing. ie... nothing-check: func [value [any-type!]][ either value? 'value [join "that was: " value]['nothing...] ]
>> nothing-check "abc"
== "that was: abc"
>> nothing-check print "abc"
abc == nothing...
>> nothing-check join "abc" "xyz"
== "that was: abcxyz"
>> nothing-check
== nothing... HTH! Carl. PS: And 'focus in VID returns nothing too. (; On 28-Aug-02, Ed Dana wrote:
> OK, so what's going on here. > I'm trying to put a little error handling around my application. If > it fails, I need it to send out an alarm. But, depending on the > statement, I get an error when trying to trap the error. > For example, this works as expected: >>> If Error? Fred: Try [ 1 / 0 ] [ Print "Whatever!" ] > Whatever! > As does this: >>> If Error? Fred: Try [ 1 / 1 ] [ Print "Whatever!" ] > == none > This too: >>> If Error? Fred: Try [ Print ] [ Print "Whatever!" ] > Whatever! > But this doesn't: >>> If Error? Fred: Try [ Print "Get a grip!" ] [ Print "Whatever!" > ] Get a grip! > ** Script Error: Fred needs a value ** Near: If Error? Fred: Try > [Print "Get a grip!"] > This is confusing because why should I get an error on something > that doesn't and shouldn't cause an error. > This works, of course: >>> If Error? Fred: Try [ x: 1 ] [ Print "Whatever!" ] > == none > And this: >>> If Error? Fred: Try [ x: 1 / 0 ] [ Print "Whatever!" ] > Whatever! > And so do these: >>> If Error? Fred: Try [ Do [ 1 / 0 ] ] [ Print "Whatever!" ] > Whatever! >>> If Error? Fred: Try [ Do [ 1 / 1 ] ] [ Print "Whatever!" ] > == none > What's perplexing about the previous two is that it is a "Do" > statement that I am trying to execute and trap. Instead of > functioning as above, it blows up and gives me the "needs a value > error". > And curiously, not only does Print fail, but so does Write. And that > is a function that I need error trapping on, if ever there was one. >>> If Error? Fred: Try [ Write %Temp.txt "Yup!" ] [ Print > "Whatever!" ] ** Script Error: Fred needs a value ** Near: If Error? > Fred: Try [Write %Temp.txt "Yup!"] > I've even tried disarming the error, but to no avail: >>> If Error? Fred: Try [ Write %Temp.txt "Yup!" ] [ Print "Whatever!" >>> ] Disarm Fred > ** Script Error: Fred needs a value > ** Near: If Error? Fred: Try [Write %Temp.txt "Yup!"] > So what gives? Is this some subtle intricacy of the language, a bug, > or my normal state of confusion?
-- Carl Read