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

[REBOL] Re: Don't understand "try" and "disarm"

From: swhite:ci:bloomington:mn:us at: 14-Mar-2006 9:58

Well, I am slowly beginning to understand my own question. The previously-submitted test script left out the obvious fourth option of trying to read a file that does NOT exist and then writing it. That operation "works" also, as in reporting the error of the file not existing. (The revised script is at the end of the message.) Of the four options, the script crashes when it tries to read a file that DOES exist and write it to another file. It crashes only when it works. According to the REBOL dictionary, "try" returns either an error or THE RESULT OF THE BLOCK. So, if I comment-out things so the script tries to read a file that does not exist, FTP-RESULT is an error. If I comment-out things so the script just reads a file that does exist, FTP-RESULT is a a string. A string is the result of reading a text file. The script crashes when it tries to write a file. What is the "result" of a block that writes a file? That, perhaps, is what I don't understand. My actual mission is to write a script that transfers a file from one computer to another by FTP, and not crash if the file is not there, or if the transfer fails in some way. Maybe I am trying to do this the wrong way. Thank you for any advice. ;;;; revised test script REBOL [ ] TRANSFER-FILE: does [ either error? FTP-RESULT: try [ ;;;; read %nonexistent.txt ;;;;; this file does NOT exist ;;;; read %fileexists.txt ;;;;; This file DOES exist ;;;; write %tempfile.txt read %nonexistent.txt write %tempfile.txt read %fileexists.txt ;;;; this crashed ] ;;;;;; -- There was some error [ FTP-ERROR-OBJECT: disarm FTP-RESULT FTP-ERROR-MESSAGE: rejoin [ "The file was not transferred." " The REBOL interpreter returned the following message: " to-string FTP-ERROR-OBJECT/id ] alert FTP-ERROR-MESSAGE ] ;;;;;; -- There was no error [ alert "The file was read successfully" ] ] view layout [ title "Test the script" button "GO" [TRANSFER-FILE] ] ;;;; end of test script Steven White City of Bloomington 1800 W Old Shakopee Rd Bloomington MN 55431-3096 USA 952-563-4882 (voice) 952-563-4672 (fax)