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

And another stumper....

 [1/8] from: kpeters::otaksoft::com at: 29-Aug-2007 18:47


I am testing my code and run the function below against a non-existent mysql server: Hmm - thought that try should catch this but apparently other things= happen: mysql-query: function [ {Either returns [["ERROR"]], [["EMPTY"]] or [[= <cursor> ]]} querystr [string!] statusbar [object! none!]] [= cursor ] [ print "about to open port" mysql-error: try [ mysqlport: open mysql-url cursor: send-sql mysqlport querystr close mysqlport false ; no error if we get here! ] either error? mysql-error [ probe mysql-error mysql-error: disarm mysql-error if statusbar <> none [ stat-upd sbar reform [= "MySQL-Connection error: " mysql-error/arg1 ]] return [["ERROR"]] ] [ either cursor = [] [ return [[ "EMPTY" ]] ] [ return cursor ] = ] ] about to open port ** Access Error: Cannot connect to 192.168.1.220 ** Where: open-proto ** Near: mysqlport: open mysql-url cursor: send-sql >> Can someone fill me in how that's possible? Thanks Kai

 [2/8] from: tim-johnsons:web at: 29-Aug-2007 18:48


On Wednesday 29 August 2007, Kai Peters wrote:
> I am testing my code and run the function below against a non-existent
Hi Kai: End of a long day here and between my mailer and yours, I think I am seeing things that you didn't originally code - *but*, I believe that you need to 'disarm the error object. See help disarm and the current documentation on error handling. talk to you later tim

 [3/8] from: kpeters:otaksoft at: 29-Aug-2007 20:07


Tim ~ There is a disarm (right below the probe... line) If I only knew how to tame my mailer...!! Kai On Wed, 29 Aug 2007 18:48:44 -0800, Tim Johnson wrote:

 [4/8] from: anton:wilddsl:au at: 30-Aug-2007 13:55


Kai, Tim is correct, you have to be more careful handling errors. Example, this is not enough to trap the error: my-error: try [1 / 0] disarm my-error In the first expression above, the set-word looks for a value, and gets an error from TRY. The result returned is the value of the set-word, which is the error, so it is left to "explode". You can do this: disarm my-error: try [...] but that assumes that there always will be an error. It will fail when your code does not make an error: disarm my-error: try [print 100] So a way that handles all errors and normal return values is: if error? set/any 'my-error try [...][ print mold disarm my-error ] Yes, it is quite wordy, but it's possible to refactor into helper functions, as Ladislav has done. Regards, Anton.

 [5/8] from: kpeters::otaksoft::com at: 30-Aug-2007 11:36


On Thu, 30 Aug 2007 13:55:38 +1000, Anton Rolls wrote:
> if error? set/any 'my-error try [...][ print > mold disarm my-error ]
Anton ~ thanks for taking the time to explain this in such detail. I believe I now understand much better what I did wrong here. Regards, Kai

 [6/8] from: kpeters:otaksoft at: 30-Aug-2007 12:20


... or so I thought - same error with revised code (my old code commented out) Please bear with me one more time... Thanks Kai ;-------------------------------------------------------------------------------------------------- mysql-query: function [ {Either returns [["ERROR"]], [["EMPTY"]] or [[<cursor>]} querystr [string!] statusbar [object! none!]] [ cursor ] [ print "about to open port" if error? set/any 'mysql-error try [ mysqlport: open mysql-url cursor: send-sql mysqlport querystr close mysqlport ][ disarm mysql-error if statusbar <> none [ stat-upd statusbar reform [ "MySQL-Connection error: " mysql-error/arg1 ]] return [["ERROR"]] ] either cursor = [] [ return [[ "EMPTY" ]] ] [ return cursor ] ] ; mysql-error: try [ ; mysqlport: open mysql-url ; cursor: send-sql mysqlport querystr ; close mysqlport ; ] ; either error? mysql-error [ ; mysql-error: disarm mysql-error ; if statusbar <> none [ stat-upd sbar reform [ "MySQL-Connection error: " mysql-error/arg1 ]] ; return [["ERROR"]] ; ][ either cursor = [] [ return [[ "EMPTY" ]] ] [ return cursor ]] ;] about to open port ** Access Error: Cannot connect to 192.168.1.220 ** Where: open-proto ** Near: mysqlport: open mysql-url cursor: send-sql

 [7/8] from: tim-johnsons::web::com at: 30-Aug-2007 15:22


On Wednesday 29 August 2007, Kai Peters wrote:
> I am testing my code and run the function below against a non-existent > mysql server: > > Hmm - thought that try should catch this but apparently other things > happen:
Kai, below is a basic code framework that I use for my rebol CGI scripts. Most relevant to error handling is the last two lines. I hope that you find this a helpful example cheers tim (code follows) ;; ====================================== application: [; execution block cgi/init ;; initialize cgi handler cgi/set[testservers: test-server-names] db-profile: ["*****" "*****" "127.0.0.1" "*****"] ;; mysql login info db[init db-profile] ;; log into mysql server main ;; code here db[close] cgi/close ] ;;====================================== ;; 'print-error is the error handling function except: [print-error disarm err ] if error? set/any 'err try application except

 [8/8] from: anton::wilddsl::net::au at: 31-Aug-2007 9:41


It looks just like OPEN is failing to connect. Maybe there is a rebol process which is still connected on that port. Check your process list. Shut down all rebol processes and start fresh to be sure there are no ports tied up. Maybe the server isn't reachable or isn't running. Have you tried each line manually in the console ? Anton.