Subject | [firebird-support] how to capture exceptions |
---|---|
Author | Adrian Allende |
Post date | 2004-08-10T03:43:49Z |
Hello all
I'm interested in exception catching, in order to put de exception in a field.
For example, in a trigger after insert/update/delete the code should be
begin
...
when exception e
new.error = e
new.usr = current_user
new.ts = current_timestamp
end
but this is not possible, in particular with user defined exceptions.
So the best aproach I find is :
begin
...
when gds_code < 0
new.field_error = gds_code
when sql_code < 0
new.field_error = sql_code
when exception=user_ex_1
new.field_error = 1 or 'user_ex_1'
when exception=user_ex_2
new.field_error = 2 or 'user_ex_2'
when exception=user_ex_3
new.field_error = 3 or 'user_ex_3'
when exception=user_ex_N
new.field_error = N or 'user_ex_N'
end
where 1 .. N are the exceptions that can raise in [ ... ] block, or all the user exceptions.
There is a better solution?
Why the user exceptions are not reported in a implicit var, like gds_code or current_user ?
Do you feel there is a need for the user_exeption variable, to use in a when block?
Thanks!
Adrián
I'm interested in exception catching, in order to put de exception in a field.
For example, in a trigger after insert/update/delete the code should be
begin
...
when exception e
new.error = e
new.usr = current_user
new.ts = current_timestamp
end
but this is not possible, in particular with user defined exceptions.
So the best aproach I find is :
begin
...
when gds_code < 0
new.field_error = gds_code
when sql_code < 0
new.field_error = sql_code
when exception=user_ex_1
new.field_error = 1 or 'user_ex_1'
when exception=user_ex_2
new.field_error = 2 or 'user_ex_2'
when exception=user_ex_3
new.field_error = 3 or 'user_ex_3'
when exception=user_ex_N
new.field_error = N or 'user_ex_N'
end
where 1 .. N are the exceptions that can raise in [ ... ] block, or all the user exceptions.
There is a better solution?
Why the user exceptions are not reported in a implicit var, like gds_code or current_user ?
Do you feel there is a need for the user_exeption variable, to use in a when block?
Thanks!
Adrián