An Example of On-Error Trigger in Oracle Forms
2016-12-25 21:11
716 查看
I wrote this trigger around 4 years ago to handle errors in an application based on Oracle Forms 6i. This trigger handles all errors with some custom messages for some specific errors and not only this after giving an appropriate message to the user it logs the error into a table named error_log, so that a DBA can view all the errors with their execution time, user and program information. See the example below:
On-Error Trigger code:
declare
vabutton number;
verrtxt varchar2(80) := error_text;
verrno number := error_code;
vdbms number := dbms_error_code;
verrtype varchar2(20) := error_type;
begin
if vdbms = -3114 or vdbms = -1017 or vdbms = -3115 or vdbms = -1012 then
-- logon related errors
set_alert_property('errmes', title, 'App '||ltrim(to_char(vdbms)));
set_alert_property('errmes', alert_message_text, 'Logon denied.');
vabutton := show_alert('errmes');
raise form_trigger_failure;
end if;
if verrno = 41009 OR VERRNO = 41008 or verrno = 40100 OR VERRNO = 40105 then
--- ignoring all errors like at first record etc.
NULL;
elsif verrno = 40509 then
insert into error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION) values
(error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
frmsave;
set_alert_property('errmes', title, 'Info.'||ltrim(to_char(verrno)));
set_alert_property('errmes', alert_message_text, 'You cannot update records.');
vabutton := show_alert('errmes');
:main.er := :main.er + 1;
else
insert into hms.error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION) values
(hms.error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
--- frmsave is the database procedure to commit explicitly.
frmsave;
set_alert_property('errmes', title, 'Info.'||ltrim(to_char(verrno)));
set_alert_property('errmes', alert_message_text, verrtxt);
vabutton := show_alert('errmes');
:main.er := :main.er + 1;
end if;
exception
when form_trigger_failure then
null;
when others then
-- FOR DEBUG NEXT LINE TO KNOW ERROR NUMBER
-- set_alert_property('errmes', alert_message_text, '['||TO_CHAR(ERROR_CODE)||'] '||error_text);
insert into error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION)values
(error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
frmsave;
set_alert_property('errmes', alert_message_text, error_text);
vabutton := show_alert('errmes');
:main.er := :main.er + 1;
end;
Error_Log Table structure:
See also: Writing On-Error Trigger in Oracle Forms
On-Error Trigger code:
declare
vabutton number;
verrtxt varchar2(80) := error_text;
verrno number := error_code;
vdbms number := dbms_error_code;
verrtype varchar2(20) := error_type;
begin
if vdbms = -3114 or vdbms = -1017 or vdbms = -3115 or vdbms = -1012 then
-- logon related errors
set_alert_property('errmes', title, 'App '||ltrim(to_char(vdbms)));
set_alert_property('errmes', alert_message_text, 'Logon denied.');
vabutton := show_alert('errmes');
raise form_trigger_failure;
end if;
if verrno = 41009 OR VERRNO = 41008 or verrno = 40100 OR VERRNO = 40105 then
--- ignoring all errors like at first record etc.
NULL;
elsif verrno = 40509 then
insert into error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION) values
(error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
frmsave;
set_alert_property('errmes', title, 'Info.'||ltrim(to_char(verrno)));
set_alert_property('errmes', alert_message_text, 'You cannot update records.');
vabutton := show_alert('errmes');
:main.er := :main.er + 1;
else
insert into hms.error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION) values
(hms.error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
--- frmsave is the database procedure to commit explicitly.
frmsave;
set_alert_property('errmes', title, 'Info.'||ltrim(to_char(verrno)));
set_alert_property('errmes', alert_message_text, verrtxt);
vabutton := show_alert('errmes');
:main.er := :main.er + 1;
end if;
exception
when form_trigger_failure then
null;
when others then
-- FOR DEBUG NEXT LINE TO KNOW ERROR NUMBER
-- set_alert_property('errmes', alert_message_text, '['||TO_CHAR(ERROR_CODE)||'] '||error_text);
insert into error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION)values
(error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
frmsave;
set_alert_property('errmes', alert_message_text, error_text);
vabutton := show_alert('errmes');
:main.er := :main.er + 1;
end;
Error_Log Table structure:
[align=center]1[/align] | SQNO | NUMBER(10) |
[align=center]2[/align] | USERNAME | VARCHAR2(20 BYTE) |
[align=center]3[/align] | ERROR_MSG | VARCHAR2(200 BYTE) |
[align=center]4[/align] | ERROR_CD | NUMBER(10) |
[align=center]5[/align] | ERROR_TP | VARCHAR2(10 BYTE) |
[align=center]6[/align] | ERROR_DT | DATE |
[align=center]7[/align] | LOCATION | VARCHAR2(20 BYTE) |
相关文章推荐
- An Example of Pre-Query and Post-Query Triggers in Oracle Forms With Using Display_Item to Highlight Dynamically
- An Example Of Validating Text Item In Oracle Forms Using When-Validate-Item Trigger
- Set Font Properties On Mouse Hover Of Push Button And Text Items At Run time In Oracle Forms
- Writing On-Error Trigger In Oracle Forms
- If Value Exists Then Query Else Allow Create New in Oracle Forms An Example
- You receive 'The remote computer disconnected the session because of an error in licensing protocol' on XP Prf
- Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
- Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server.
- ASP报错:Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the
- Oracle Invalid character ' ' in value part of property error
- 20100507 学习记录: Server Error in '/' Application. Object reference not set to an instance of an object
- An Example about the use of map Container in C++ STL / c++ map容器的用法
- Using Timer to get history values from EDNA database, an error is prompted in the page : "Sys.WebForms.PageRequestManagerTimeout
- Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The s
- Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The s
- Call multiple URLs on single click of af:goLink in Oracle ADF
- Error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server
- An error occurred during the execution of xp_cmdshell. A call to 'LogonUserW' failed with error code: '1385'
- Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the serve
- Count the number of bits that are on in an unsigned integer(计算一个无符整数中1Bit的个数)-- (1)