Home   Archive   Permalink



Android R3 error trapping

Hi Folks,
    
Have just stumbled upon REBOL and have just started working my way through the Android version and the examples in this document: http://learnrebol.com/rebol3_book.html
    
In the process of trying to implement what I'm learning I created a simple script to both read and write temp.txt. Now, if you try to read first and the file doesn't exist, then it falls over with an error - understandably. So I tried to put in some error trapping as per the same document, with the intention that once it has trapped the error you can continue using the application. But what happens is this: Regardless of whether temp.txt exists already or not, iff you click on 'read' it shows the alert. Then, once you click on the 'ok' button, it then crashes and says,
    
** script error: if does not allow object! for its then-block argument
** where: actor all foreach do-actor unless do-face if actor all foreach do-actor if do-event do-event if do-event either - apply- wake-up loop -apply- wait forever try do-events if view do either either either -apply-
** Near: actor face :data
    
So, I'm not quite sure what that means. What did I do wrong? And how do I achieve what I intended?
    
Any input gratefully received.
    
Mike Hersee
    
Here's the code:
R E B O L [title: "here"]
do %r3-gui.r3
view [ a: area
     button "read" on-action [if not attempt [set-face a read/string %temp.txt] alert "file not found"]
     button "write" on-action [write %temp.txt get-face a
         alert "saved"]
     ]


posted by:   Mike Hersee       23-Mar-2014/6:54:44-7:00



Ok, I just got a bit further and noticed almost exactly this situation is already handled.

posted by:   Mike Hersee       23-Mar-2014/7:39:35-7:00



Hi Mike,
    
In general, be aware that errors errors are usually handled with:
    
if error? try [<some code>][error handler]

posted by:   Nick       23-Mar-2014/9:11:56-7:00