This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Catch error

Help for those learning Tcl or writing their own scripts.
Post Reply
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Catch error

Post by garfwen »

Hello

Code: Select all

<Eggdrop> [XX:XX] Tcl error [my_proc]: ::mysql::sel/db server: MySQL server has gone away
is there any way to catch this error? and execute something when it catches?

Thank you
GaRfWeN
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Use the "catch" command with each ::mysql::* command? (works for any other command that would throw an error, as well).

Workflow would be something like this:

Code: Select all

if {[catch {::mysql::sel "SELECT * FROM `Yourtable`" -list} result]} {
  putlog "An error occured while retrieving data from `Yourtable`. The error was \"$result\"."
} {
  putlog "Retrieved data from `Yourtable`:"
  foreach item $result {
    putlog "data: [join $item ", "]"
  }
}
In the case of an error, you'll also find extended information on the error in the ::errorInfo and ::errorCode variables (putlog $::errorCode or such).
NML_375
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Post by garfwen »

Thanks.
Post Reply