Forum OpenACS Development: CATCH

Collapse
1: CATCH
Posted by Judith Pino Chial on
Hi.

I'll like to know if "catch" works in OpenACS.

Collapse
2: Re: CATCH (response to 1)
Posted by Brad Duell on
Yup. For ex:

if { [catch [db_1row select_none "select user_id from users where user_id=-100"]] } {
#Do something
} else {
#Do something else
}

Works.

Collapse
3: Re: CATCH (response to 1)
Posted by Judith Pino Chial on
Hi Brad.

That means that :
...
set db [ns_db gethandle]
if { [catch { db_dml $db "SQL" } errmsg] }  {forward page_error?}

ns_db releasehandle $db
....

it's ok?

Collapse
4: Re: CATCH (response to 1)
Posted by Brian Fenton on
Hi Judith!
what does forward page_error mean?

Something to watch out for is how you use curly braces with the "if" command. Always put your newline between 2 curly braces e.g.

set db [ns_db gethandle]
if { [catch { db_dml $db "SQL" } errmsg] } {
forward page_error?
}

ns_db releasehandle $db
....

See Philip Greenspun's TCL book:
http://philip.greenspun.com/tcl/control-structure.adp

Collapse
5: Re: CATCH (response to 1)
Posted by Judith Pino Chial on
page_error it's a adp file that contains a message( this information is been used.... You can't delete it).
Collapse
6: Re: CATCH (response to 1)
Posted by Brian Fenton on
Oh right, so forward is template::forward. So does the catch work ok?
Collapse
7: Re: CATCH (response to 1)
Posted by Judith Pino Chial on
Yes, the catch it's ok

Thank You very Much Brian and Brad!!!