Exception handling in App. package PeopleCode
Hi,
I am accessing a table that is on remote database using DBLink for an update/insert operation using SQLExec. I am trying to implement exception handling to account for the scenario where the remote database is offline so that transaction can continue. However when I use the try-catch block in the app. package PeopleCode somehow the processing does not seem to move forward from the error. The App. pacakage code is triggered by the handler of the service operation. The goal is to simply skip the SQLExec if the table is not available. I am not sure if there is any limitation to the fatal SQL errors which the try-catch can handle.
As expected i get below error when running select on a view which has remote table in the SQL developer as remote database is down.
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Has anyone enconutered similar issue with exception handling and best way to move forward in this scenario.
Any response is much appreciated.
Thanks,
Gireesh
I did this with PL/SQL once. Basically, you want to know if the remote database is available before you execute SQL against it. Here is my function. You can then SQLExec something like select 'x' from dual where my_package.link_available('the_link_name') = 1. If you get a result, then the db link is active. If you don't, it is not active.
FUNCTION LINK_AVAILABLE(pv_name VARCHAR2)
RETURN NUMBER AS
lv_result PLS_INTEGER;
lv_name VARCHAR2(128);
BEGIN
lv_name := UPPER(pv_name);
-- parameter check to avoid SQL injection with dynamic SQL below
-- if the following selects no rows, it will fall through to exception
-- and return 0;
SELECT 1
INTO lv_result
FROM ALL_DB_LINKS
WHERE DB_LINK = lv_name;
-- if we made it this far, then the parameter was a valid db link name
-- execute SQL to test
EXECUTE IMMEDIATE 'SELECT 1 FROM PS_INSTALLATION@' || lv_name INTO lv_result;
RETURN lv_result;
EXCEPTION
WHEN OTHERS THEN
RETURN 0;
END LINK_AVAILABLE;
Similar Messages
-
Public exception handler in database package
I'm working on Oracle 10 g; I have a package with 10 functions, instead of writing exception for each individually is there is a way to do the same exception handler in all without repeating the exception handler in the 10 function (my exception handler is the same for the 10 function)
It would depend on how you are using the functions, and what exactly your exception handler does.
If, for example, your handler for no_data_found does a specific select statement, then you could put this statement in another function and call that function in the exception handler of each of the 10 functions. Note that you would need to catch the exception in eacg function, but the common code would be in one place. Something like:
FUNCTION error_func RETURN NUMBER IS
BEGIN
SELECT other_stuff INTO var;
RETURN var;
END;
function1 RETURN NUMBER IS;
BEGIN
SELECT stuff INTO var;
RETURN var;
EXCEPTION
WHEN NO_DATA_FOUND
effor_func;
END;
function2 RETURN NUMBER IS;
BEGIN
SELECT stuff INTO var;
RETURN var;
EXCEPTION
WHEN NO_DATA_FOUND
effor_func;
END;
function3 RETURN NUMBER IS;
BEGIN
SELECT stuff INTO var;
RETURN var;
EXCEPTION
WHEN NO_DATA_FOUND
effor_func;
END;If you always run all 10 functions in sequence, then you could make a wrapper to call the functions, and catch exceptions in the wrapper. Something along the lines of:
FUNCTION wrapper RETURN NUMBER IS;
BEGIN
function1;
function2;
function10;
EXCEPTION
WHEN NO_DATA_FOUND THEN
do something;
END;As constructed here, the wrapper wil not know which function errored nor will it continue running the other functions after getting an error.
John -
Provider Hosted App - Exception Handling and Logging
Hello,
I would like to use file system to log the exceptions (The IIS server in which the APP is configured) for Provider Hosted App - Could anyone share some blogs/links related to that?
Thanks in advance,Well the first time, I asked the question, I think I
was not so clear. Please let me explain this in
detail. I am not architect, so correct me if I am
wrong.
I want to use log4J but definitely want to avoid using
them directly in our package, idea is to create
wrappers around all the external API, jar we are
using. At logging side I feel little comfortable.
But having little difficulty in thinking and designing
about Exception handling framework.
1. My aim is to create a general framework in 3 broad
categories (For Presentation tier, For Business tier,
for Data Access tier)
2. For each tier if you import those already created
framework classes, all developers should be just able
to use the methods of exception framework and use them
in catch block and throw them.
Example:- I would like to create a class called
MyProjectExceptionDecider, which will decide the type
of exception in Business Tier and then use my
MyProjectExceptionErrorParser, which reads the XML
document and gets a related message number and error
message.
This MyProjectExceptionErrorParser then passes the
right exception to MyProjectExceptionDisplayer which
will display the exception with right message and
message number.
And something more like this. I am not yet getting
complete picture.
3. So, if you have done something similar and if you
have the class diagram and sequence diagram for such
exception handling, I would be grateful if you are
willing to share with me.
Please let me know, if you have different ideas. I
request you all to participate and throw your ideas
and suggestions.
Srikanthgenerally, wheather or not you are using log4j or anything else, when designing exception handling mechnism, you need to decide on where or by whom an exception will be handled, and if the exception needs to be displyed, and how it is displayed. -
Exception Handling in packages called from forms
I am running 10g forms that have many calls to packages/procedures in the database. I am seeing hanging processes on the web server (even after forms processes are stopped) and 1 of the causes Oracle listed was not having proper exception handling in the procesdures. Do I need to add an Exception (' when others then null') to my package specs to handle this?
"Do I need to add an Exception (' when others then null') to my package specs to handle this? "
That will hide the problem not handle it. You really need is to find out where the code is failing...
There is a method for logging message for debugging here...
http://oracle-developer.net/display.php?id=424
An another which is less good for a live system (the one above lets you set different levels of importance for logs messages and can be turned on or off for each user) but looks easier to implement in case you might be in a hurry...
Re: Zdebug -- Download a Forms debugging message tool -
'Install App for SharePoint' There were errors when validating the App Package
Hello,
When testing with an app, I tried to add an
app event receiver before learning that remote event receiver are not allowed with
Sharepoint-hosted app. So I reseted the Handle app installed and
Web Project properties of my project and tried to redeploy and this error occurred :
'Install App for SharePoint' There were errors when validating the App Package
Something other than the project's properties have been modified but I don't know what.I think the best way to figure real reason out is to look at ULS logs.
This is example, what I had:
Unexpected App Packaging: CreatePackage: Unexpected exception: There were errors when validating the App package: There were errors when validating the App Package. Other warnings / errors associated with this
exception: The current version of SharePoint is less than the SharePointMinVersion specified in the app manifest. CurrentVersion='15.0.4693.1000', SharePointMinVersion='16.0.0.0'. -
PL/SQL 101 : Exception Handling
Frequently I see questions and issues around the use of Exception/Error Handling in PL/SQL. More often than not the issue comes from the questioners misunderstanding about how PL/SQL is constructed and executed, so I thought I'd write a small article covering the key concepts to give a clear picture of how it all hangs together. (Note: the examples are just showing examples of the exception handling structure, and should not be taken as truly valid code for ways of handling things)
Exception Handling
Contents
1. Understanding Execution Blocks (part 1)
2. Execution of the Execution Block
3. Exceptions
4. Understanding Execution Blocks (part 2)
5. How to continue exection of statements after an exception
6. User defined exceptions
7. Line number of exception
8. Exceptions within code within the exception block
1. Understanding Execution Blocks (part 1)
The first thing that one needs to understand is almost taking us back to the basics of PL/SQL... how a PL/SQL execution block is constructed.
Essentially an execution block is made of 3 sections...
+---------------------------+
| Declaration Section |
+---------------------------+
| Statements Section |
+---------------------------+
| Exception Section |
+---------------------------+
The Declaration section is the part defined between the PROCEDURE/FUNCTION header or the DECLARE keyword (for anonymous blocks) and the BEGIN keyword. (Optional section)
The Statements section is where your code goes and lies between the BEGIN keyword and the EXCEPTION keyword (or END keyword if there is no EXCEPTION section). (Mandatory section)
The Exception section is where any exception handling goes and lies between the EXCEPTION keyword at the END keyword. (Optional section)
Example of an anonymous block...
DECLARE
.. declarative statements go here ..
BEGIN
.. code statements go here ..
EXCEPTION
.. exception handlers go here ..
END;
Example of a procedure/function block...
[CREATE OR REPLACE] (PROCEDURE|FUNCTION) <proc or fn name> [(<parameters>)] [RETURN <datatype>] (IS|AS)
.. declarative statements go here ..
BEGIN
.. code statements go here ..
EXCEPTION
.. exception handlers go here ..
END;
(Note: The same can also be done for packages, but let's keep it simple)
2. Execution of the Execution Block
This may seem a simple concept, but it's surprising how many people have issues showing they haven't grasped it. When an Execution block is entered, the declaration section is processed, creating a scope of variables, types , cursors, etc. to be visible to the execution block and then execution enters into the Statements section. Each statment in the statements section is executed in turn and when the execution completes the last statment the execution block is exited back to whatever called it.
3. Exceptions
Exceptions generally happen during the execution of statements in the Statements section. When an exception happens the execution of statements jumps immediately into the exception section. In this section we can specify what exceptions we wish to 'capture' or 'trap' and do one of the two following things...
(Note: The exception section still has access to all the declared items in the declaration section)
3.i) Handle the exception
We do this when we recognise what the exception is (most likely it's something we expect to happen) and we have a means of dealing with it so that our application can continue on.
Example...
(without the exception handler the exception is passed back to the calling code, in this case SQL*Plus)
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_name VARCHAR2(20);
3 begin
4 select ename
5 into v_name
6 from emp
7 where empno = &empno;
8 dbms_output.put_line(v_name);
9* end;
SQL> /
Enter value for empno: 123
old 7: where empno = &empno;
new 7: where empno = 123;
declare
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 4
(with an exception handler, we capture the exception, handle it how we want to, and the calling code is happy that there is no error for it to report)
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_name VARCHAR2(20);
3 begin
4 select ename
5 into v_name
6 from emp
7 where empno = &empno;
8 dbms_output.put_line(v_name);
9 exception
10 when no_data_found then
11 dbms_output.put_line('There is no employee with this employee number.');
12* end;
SQL> /
Enter value for empno: 123
old 7: where empno = &empno;
new 7: where empno = 123;
There is no employee with this employee number.
PL/SQL procedure successfully completed.
3.ii) Raise the exception
We do this when:-
a) we recognise the exception, handle it but still want to let the calling code know that it happened
b) we recognise the exception, wish to log it happened and then let the calling code deal with it
c) we don't recognise the exception and we want the calling code to deal with it
Example of b)
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_name VARCHAR2(20);
3 v_empno NUMBER := &empno;
4 begin
5 select ename
6 into v_name
7 from emp
8 where empno = v_empno;
9 dbms_output.put_line(v_name);
10 EXCEPTION
11 WHEN no_data_found THEN
12 INSERT INTO sql_errors (txt)
13 VALUES ('Search for '||v_empno||' failed.');
14 COMMIT;
15 RAISE;
16* end;
SQL> /
Enter value for empno: 123
old 3: v_empno NUMBER := &empno;
new 3: v_empno NUMBER := 123;
declare
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 15
SQL> select * from sql_errors;
TXT
Search for 123 failed.
SQL>
Example of c)
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_name VARCHAR2(20);
3 v_empno NUMBER := &empno;
4 begin
5 select ename
6 into v_name
7 from emp
8 where empno = v_empno;
9 dbms_output.put_line(v_name);
10 EXCEPTION
11 WHEN no_data_found THEN
12 INSERT INTO sql_errors (txt)
13 VALUES ('Search for '||v_empno||' failed.');
14 COMMIT;
15 RAISE;
16 WHEN others THEN
17 RAISE;
18* end;
SQL> /
Enter value for empno: 'ABC'
old 3: v_empno NUMBER := &empno;
new 3: v_empno NUMBER := 'ABC';
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 3
SQL> select * from sql_errors;
TXT
Search for 123 failed.
SQL>
As you can see from the sql_errors log table, no log was written so the WHEN others exception was the exception that raised the error to the calling code (SQL*Plus)
4. Understanding Execution Blocks (part 2)
Ok, so now we understand the very basics of an execution block and what happens when an exception happens. Let's take it a step further...
Execution blocks are not just a single simple block in most cases. Often, during our statements section we have a need to call some reusable code and we do that by calling a procedure or function. Effectively this nests the procedure or function's code as another execution block within the current statement section so, in terms of execution, we end up with something like...
+---------------------------------+
| Declaration Section |
+---------------------------------+
| Statements Section |
| . |
| +---------------------------+ |
| | Declaration Section | |
| +---------------------------+ |
| | Statements Section | |
| +---------------------------+ |
| | Exception Section | |
| +---------------------------+ |
| . |
+---------------------------------+
| Exception Section |
+---------------------------------+
Example... (Note: log_trace just writes some text to a table for tracing)
SQL> create or replace procedure a as
2 v_dummy NUMBER := log_trace('Procedure A''s Declaration Section');
3 begin
4 v_dummy := log_trace('Procedure A''s Statement Section');
5 v_dummy := 1/0; -- cause an exception
6 exception
7 when others then
8 v_dummy := log_trace('Procedure A''s Exception Section');
9 raise;
10 end;
11 /
Procedure created.
SQL> create or replace procedure b as
2 v_dummy NUMBER := log_trace('Procedure B''s Declaration Section');
3 begin
4 v_dummy := log_trace('Procedure B''s Statement Section');
5 a; -- HERE the execution passes to the declare/statement/exception sections of A
6 exception
7 when others then
8 v_dummy := log_trace('Procedure B''s Exception Section');
9 raise;
10 end;
11 /
Procedure created.
SQL> exec b;
BEGIN b; END;
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.B", line 9
ORA-06512: at line 1
SQL> select * from code_trace;
TXT
Procedure B's Declaration Section
Procedure B's Statement Section
Procedure A's Declaration Section
Procedure A's Statement Section
Procedure A's Exception Section
Procedure B's Exception Section
6 rows selected.
SQL>
Likewise, execution blocks can be nested deeper and deeper.
5. How to continue exection of statements after an exception
One of the common questions asked is how to return execution to the statement after the one that created the exception and continue on.
Well, firstly, you can only do this for statements you expect to raise an exception, such as when you want to check if there is no data found in a query.
If you consider what's been shown above you could put any statement you expect to cause an exception inside it's own procedure or function with it's own exception section to handle the exception without raising it back to the calling code. However, the nature of procedures and functions is really to provide a means of re-using code, so if it's a statement you only use once it seems a little silly to go creating individual procedures for these.
Instead, you nest execution blocks directly, to give the same result as shown in the diagram at the start of part 4 of this article.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure b (p_empno IN VARCHAR2) as
2 v_dummy NUMBER := log_trace('Procedure B''s Declaration Section');
3 begin
4 v_dummy := log_trace('Procedure B''s Statement Section');
5 -- Here we start another execution block nested in the first one...
6 declare
7 v_dummy NUMBER := log_trace('Nested Block Declaration Section');
8 begin
9 v_dummy := log_trace('Nested Block Statement Section');
10 select empno
11 into v_dummy
12 from emp
13 where empno = p_empno; -- Note: the parameters and variables from
parent execution block are available to use!
14 exception
15 when no_data_found then
16 -- This is an exception we can handle so we don't raise it
17 v_dummy := log_trace('No employee was found');
18 v_dummy := log_trace('Nested Block Exception Section - Exception Handled');
19 when others then
20 -- Other exceptions we can't handle so we raise them
21 v_dummy := log_trace('Nested Block Exception Section - Exception Raised');
22 raise;
23 end;
24 -- ...Here endeth the nested execution block
25 -- As the nested block handled it's exception we come back to here...
26 v_dummy := log_trace('Procedure B''s Statement Section Continued');
27 exception
28 when others then
29 -- We'll only get to here if an unhandled exception was raised
30 -- either in the nested block or in procedure b's statement section
31 v_dummy := log_trace('Procedure B''s Exception Section');
32 raise;
33* end;
SQL> /
Procedure created.
SQL> exec b(123);
PL/SQL procedure successfully completed.
SQL> select * from code_trace;
TXT
Procedure B's Declaration Section
Procedure B's Statement Section
Nested Block Declaration Section
Nested Block Statement Section
No employee was found
Nested Block Exception Section - Exception Handled
Procedure B's Statement Section Continued
7 rows selected.
SQL> truncate table code_trace;
Table truncated.
SQL> exec b('ABC');
BEGIN b('ABC'); END;
ERROR at line 1:
ORA-01722: invalid number
ORA-06512: at "SCOTT.B", line 32
ORA-06512: at line 1
SQL> select * from code_trace;
TXT
Procedure B's Declaration Section
Procedure B's Statement Section
Nested Block Declaration Section
Nested Block Statement Section
Nested Block Exception Section - Exception Raised
Procedure B's Exception Section
6 rows selected.
SQL>
You can see from this that, very simply, the code that we expected may have an exception was able to either handle the exception and return to the outer execution block to continue execution, or if an unexpected exception occurred then it was able to be raised up to the outer exception section.
6. User defined exceptions
There are three sorts of 'User Defined' exceptions. There are logical situations (e.g. business logic) where, for example, certain criteria are not met to complete a task, and there are existing Oracle errors that you wish to give a name to in order to capture them in the exception section. The third is raising your own exception messages with our own exception numbers. Let's look at the first one...
Let's say I have tables which detail stock availablility and reorder levels...
SQL> select * from reorder_level;
ITEM_ID STOCK_LEVEL
1 20
2 20
3 10
4 2
5 2
SQL> select * from stock;
ITEM_ID ITEM_DESC STOCK_LEVEL
1 Pencils 10
2 Pens 2
3 Notepads 25
4 Stapler 5
5 Hole Punch 3
SQL>
Now, our Business has told the administrative clerk to check stock levels and re-order anything that is below the re-order level, but not to hold stock of more than 4 times the re-order level for any particular item. As an IT department we've been asked to put together an application that will automatically produce the re-order documents upon the clerks request and, because our company is so tight-ar*ed about money, they don't want to waste any paper with incorrect printouts so we have to ensure the clerk can't order things they shouldn't.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 from stock s join reorder_level r on (s.item_id = r.item_id)
7 where s.item_id = p_item_id;
8 --
9 v_stock cur_stock_reorder%ROWTYPE;
10 begin
11 OPEN cur_stock_reorder;
12 FETCH cur_stock_reorder INTO v_stock;
13 IF cur_stock_reorder%NOTFOUND THEN
14 RAISE no_data_found;
15 END IF;
16 CLOSE cur_stock_reorder;
17 --
18 IF v_stock.stock_level >= v_stock.reorder_level THEN
19 -- Stock is not low enough to warrant an order
20 DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
21 ELSE
22 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
23 -- Required amount is over-ordering
24 DBMS_OUTPUT.PUT_LINE('Quantity specified is too much. Max for this item: '
||to_char(v_stock.reorder_limit-v_stock.stock_level));
25 ELSE
26 DBMS_OUTPUT.PUT_LINE('Order OK. Printing Order...');
27 -- Here goes our code to print the order
28 END IF;
29 END IF;
30 --
31 exception
32 WHEN no_data_found THEN
33 CLOSE cur_stock_reorder;
34 DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
35* end;
SQL> /
Procedure created.
SQL> exec re_order(10,100);
Invalid Item ID.
PL/SQL procedure successfully completed.
SQL> exec re_order(3,40);
Stock has not reached re-order level yet!
PL/SQL procedure successfully completed.
SQL> exec re_order(1,100);
Quantity specified is too much. Max for this item: 70
PL/SQL procedure successfully completed.
SQL> exec re_order(2,50);
Order OK. Printing Order...
PL/SQL procedure successfully completed.
SQL>
Ok, so that code works, but it's a bit messy with all those nested IF statements. Is there a cleaner way perhaps? Wouldn't it be nice if we could set up our own exceptions...
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 from stock s join reorder_level r on (s.item_id = r.item_id)
7 where s.item_id = p_item_id;
8 --
9 v_stock cur_stock_reorder%ROWTYPE;
10 --
11 -- Let's declare our own exceptions for business logic...
12 exc_not_warranted EXCEPTION;
13 exc_too_much EXCEPTION;
14 begin
15 OPEN cur_stock_reorder;
16 FETCH cur_stock_reorder INTO v_stock;
17 IF cur_stock_reorder%NOTFOUND THEN
18 RAISE no_data_found;
19 END IF;
20 CLOSE cur_stock_reorder;
21 --
22 IF v_stock.stock_level >= v_stock.reorder_level THEN
23 -- Stock is not low enough to warrant an order
24 RAISE exc_not_warranted;
25 END IF;
26 --
27 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
28 -- Required amount is over-ordering
29 RAISE exc_too_much;
30 END IF;
31 --
32 DBMS_OUTPUT.PUT_LINE('Order OK. Printing Order...');
33 -- Here goes our code to print the order
34 --
35 exception
36 WHEN no_data_found THEN
37 CLOSE cur_stock_reorder;
38 DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
39 WHEN exc_not_warranted THEN
40 DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
41 WHEN exc_too_much THEN
42 DBMS_OUTPUT.PUT_LINE('Quantity specified is too much. Max for this item: '
||to_char(v_stock.reorder_limit-v_stock.stock_level));
43* end;
SQL> /
Procedure created.
SQL> exec re_order(10,100);
Invalid Item ID.
PL/SQL procedure successfully completed.
SQL> exec re_order(3,40);
Stock has not reached re-order level yet!
PL/SQL procedure successfully completed.
SQL> exec re_order(1,100);
Quantity specified is too much. Max for this item: 70
PL/SQL procedure successfully completed.
SQL> exec re_order(2,50);
Order OK. Printing Order...
PL/SQL procedure successfully completed.
SQL>
That's better. And now we don't have to use all those nested IF statements and worry about it accidently getting to code that will print the order out as, once one of our user defined exceptions is raised, execution goes from the Statements section into the Exception section and all handling of errors is done in one place.
Now for the second sort of user defined exception...
A new requirement has come in from the Finance department who want to have details shown on the order that show a re-order 'indicator' based on the formula ((maximum allowed stock - current stock)/re-order quantity), so this needs calculating and passing to the report...
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
7 from stock s join reorder_level r on (s.item_id = r.item_id)
8 where s.item_id = p_item_id;
9 --
10 v_stock cur_stock_reorder%ROWTYPE;
11 --
12 -- Let's declare our own exceptions for business logic...
13 exc_not_warranted EXCEPTION;
14 exc_too_much EXCEPTION;
15 begin
16 OPEN cur_stock_reorder;
17 FETCH cur_stock_reorder INTO v_stock;
18 IF cur_stock_reorder%NOTFOUND THEN
19 RAISE no_data_found;
20 END IF;
21 CLOSE cur_stock_reorder;
22 --
23 IF v_stock.stock_level >= v_stock.reorder_level THEN
24 -- Stock is not low enough to warrant an order
25 RAISE exc_not_warranted;
26 END IF;
27 --
28 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
29 -- Required amount is over-ordering
30 RAISE exc_too_much;
31 END IF;
32 --
33 DBMS_OUTPUT.PUT_LINE('Order OK. Printing Order...');
34 -- Here goes our code to print the order, passing the finance_factor
35 --
36 exception
37 WHEN no_data_found THEN
38 CLOSE cur_stock_reorder;
39 DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
40 WHEN exc_not_warranted THEN
41 DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
42 WHEN exc_too_much THEN
43 DBMS_OUTPUT.PUT_LINE('Quantity specified is too much. Max for this item: '
||to_char(v_stock.reorder_limit-v_stock.stock_level));
44* end;
SQL> /
Procedure created.
SQL> exec re_order(2,40);
Order OK. Printing Order...
PL/SQL procedure successfully completed.
SQL> exec re_order(2,0);
BEGIN re_order(2,0); END;
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.RE_ORDER", line 17
ORA-06512: at line 1
SQL>
Hmm, there's a problem if the person specifies a re-order quantity of zero. It raises an unhandled exception.
Well, we could put a condition/check into our code to make sure the parameter is not zero, but again we would be wrapping our code in an IF statement and not dealing with the exception in the exception handler.
We could do as we did before and just include a simple IF statement to check the value and raise our own user defined exception but, in this instance the error is standard Oracle error (ORA-01476) so we should be able to capture it inside the exception handler anyway... however...
EXCEPTION
WHEN ORA-01476 THEN
... is not valid. What we need is to give this Oracle error a name.
This is done by declaring a user defined exception as we did before and then associating that name with the error number using the PRAGMA EXCEPTION_INIT statement in the declaration section.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
7 from stock s join reorder_level r on (s.item_id = r.item_id)
8 where s.item_id = p_item_id;
9 --
10 v_stock cur_stock_reorder%ROWTYPE;
11 --
12 -- Let's declare our own exceptions for business logic...
13 exc_not_warranted EXCEPTION;
14 exc_too_much EXCEPTION;
15 --
16 exc_zero_quantity EXCEPTION;
17 PRAGMA EXCEPTION_INIT(exc_zero_quantity, -1476);
18 begin
19 OPEN cur_stock_reorder;
20 FETCH cur_stock_reorder INTO v_stock;
21 IF cur_stock_reorder%NOTFOUND THEN
22 RAISE no_data_found;
23 END IF;
24 CLOSE cur_stock_reorder;
25 --
26 IF v_stock.stock_level >= v_stock.reorder_level THEN
27 -- Stock is not low enough to warrant an order
28 RAISE exc_not_warranted;
29 END IF;
30 --
31 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
32 -- Required amount is over-ordering
33 RAISE exc_too_much;
34 END IF;
35 --
36 DBMS_OUTPUT.PUT_LINE('Order OK. Printing Order...');
37 -- Here goes our code to print the order, passing the finance_factor
38 --
39 exception
40 WHEN exc_zero_quantity THEN
41 DBMS_OUTPUT.PUT_LINE('Quantity of 0 (zero) is invalid.');
42 WHEN no_data_found THEN
43 CLOSE cur_stock_reorder;
44 DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
45 WHEN exc_not_warranted THEN
46 DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
47 WHEN exc_too_much THEN
48 DBMS_OUTPUT.PUT_LINE('Quantity specified is too much. Max for this item: '
||to_char(v_stock.reorder_limit-v_stock.stock_level));
49* end;
SQL> /
Procedure created.
SQL> exec re_order(2,0);
Quantity of 0 (zero) is invalid.
PL/SQL procedure successfully completed.
SQL>
Lastly, let's look at raising our own exceptions with our own exception numbers...
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
7 from stock s join reorder_level r on (s.item_id = r.item_id)
8 where s.item_id = p_item_id;
9 --
10 v_stock cur_stock_reorder%ROWTYPE;
11 --
12 exc_zero_quantity EXCEPTION;
13 PRAGMA EXCEPTION_INIT(exc_zero_quantity, -1476);
14 begin
15 OPEN cur_stock_reorder;
16 FETCH cur_stock_reorder INTO v_stock;
17 IF cur_stock_reorder%NOTFOUND THEN
18 RAISE no_data_found;
19 END IF;
20 CLOSE cur_stock_reorder;
21 --
22 IF v_stock.stock_level >= v_stock.reorder_level THEN
23 -- Stock is not low enough to warrant an order
24 [b]RAISE_APPLICATION_ERROR(-20000, 'Stock has not reached re-order level yet!');[/b]
25 END IF;
26 --
27 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
28 -- Required amount is over-ordering
29its nice article, have put up this one the blog
site,Nah, I don't have time to blog, but if one of the other Ace's/Experts wants to copy it to a blog with reference back to here (and all due credit given ;)) then that's fine by me.
I'd go for a book like "Selected articles by OTN members" or something. Does anybody have a list of links of all those mentioned articles?Just these ones I've bookmarked...
Introduction to regular expressions ... by CD
When your query takes too long ... by Rob van Wijk
How to pipeline a function with a dynamic number of columns? by ascheffer
PL/SQL 101 : Exception Handling by BluShadow -
Hi everyone :
I just finished an universal app was gonna publish it on the store, on windows 8.1 no problem
On Windows Phone 8.1 I got error when creating the app package for every images I declared in the app manifest
"App manifest references the image 'Assets\Tiles\StoreLogo.png' which does not have a candidate in main app package"
Here is a par of my manifest with my assets
<m3:VisualElements DisplayName="Spirit Of Metal" Square150x150Logo="Assets\Tiles\Square150x150Logo.png" Square44x44Logo="Assets\Tiles\Square44x44Logo.png" Description="SoM.WindowsPhone" ForegroundText="light" BackgroundColor="transparent">
<m3:LockScreen Notification="badgeAndTileText" BadgeLogo="Assets\BadgeLogos\BadgeLogo.png" />
<m3:DefaultTile Square71x71Logo="Assets\Tiles\Square71x71Logo.png" Wide310x150Logo="Assets\Tiles\Wide310x150Logo.png" DefaultSize="square150x150Logo">
<m3:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" />
<m3:ShowOn Tile="wide310x150Logo" />
</m3:ShowNameOnTiles>
</m3:DefaultTile>
<m3:ApplicationView MinWidth="width320" />
<!--Used in XAML Designer. DO NOT REMOVE-->
<m3:InitialRotationPreference>
<m3:Rotation Preference="portrait" />
</m3:InitialRotationPreference>
</m3:VisualElements>
I made clean, delete tempory files, restart visual studio, delete and add the picture again, open the
manifest file to check manualy the path (it is correct with backslash)... without result.
Finaly I found a fix : generate app bundle at never, as my app has no specific
assets in other language I don't understand why.
Is this a bug (and I would like to report it) or is there a reason to this exception ?
RegardsI cannot reproduce this. Can you create a very simple repro of this issue and post to OneDrive?
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions
@WSDevSol
Getting Started With Windows Azure Mobile Services development?
Click here
Getting Started With Windows Phone or Store app development?
Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support) -
Issue with exception Handling in GG
Hi,
I have bi-directional DML replication setup. I have written a code in replication parameter for handling the exception , Exception handling is working fine my replicate process is not getting ABENDED but Issue is I am not geeting any rows in EXCEPTION table.I had gone through replicat report, there I had seen GG is trying to inser duplicate records in EXCEPTION TABLE and it is failing because of that .
**Command for create Exception Table is-**
create table ggs_admin.exceptions (
rep_name varchar2(8) ,
table_name varchar2(61) ,
errno number ,
dberrmsg varchar2(4000) ,
optype varchar2(20) ,
errtype varchar2(20) ,
logrba number ,
logposition number ,
committimestamp timestamp,
CONSTRAINT pk_exceptions PRIMARY KEY (logrba, logposition, committimestamp)
USING INDEX
TABLESPACE INDX1
TABLESPACE dbdat1
My replication parameter is-
GGSCI (db) 1> view params rep2
-- Replicator parameter file to apply changes
REPLICAT rep2
ASSUMETARGETDEFS
USERID ggs_admin, PASSWORD ggs_admin
DISCARDFILE /u01/app/oracle/product/gg/dirdat/rep2_discard.dsc, PURGE
-- Start of the macro
MACRO #exception_handler
BEGIN
, TARGET ggs_admin.exceptions
, COLMAP ( rep_name = "REP2"
, table_name = @GETENV ("GGHEADER", "TABLENAME")
, errno = @GETENV ("LASTERR", "DBERRNUM")
, dberrmsg = @GETENV ("LASTERR", "DBERRMSG")
, optype = @GETENV ("LASTERR", "OPTYPE")
, errtype = @GETENV ("LASTERR", "ERRTYPE")
, logrba = @GETENV ("GGHEADER", "LOGRBA")
, logposition = @GETENV ("GGHEADER", "LOGPOSITION")
, committimestamp = @GETENV ("GGHEADER", "COMMITTIMESTAMP"))
, INSERTALLRECORDS
, EXCEPTIONSONLY;
END;
-- End of the macro
REPERROR (DEFAULT, EXCEPTION)
--REPERROR (-1, EXCEPTION)
--REPERROR (-1403, EXCEPTION)
MAP scr.order_items, TARGET scr.order_items;
MAP scr.order_items #exception_handler();
GGSCI (db) 2>view params rep2
MAP resolved (entry scr.order_items):
MAP "scr"."order_items" TARGET ggs_admin.exceptions , COLMAP ( rep_name = "REP2" , table_name = @GETENV ("GGHEADER", "TABLENAME") , errno = @GETENV ("LASTERR", "DB
ERRNUM") , dberrmsg = @GETENV ("LASTERR", "DBERRMSG") , optype = @GETENV ("LASTERR", "OPTYPE") , errtype = @GETENV ("LASTERR", "ERRTYPE") , logrba = @GETENV ("GGHEADER"
, "LOGRBA") , logposition = @GETENV ("GGHEADER", "LOGPOSITION") , committimestamp = @GETENV ("GGHEADER", "COMMITTIMESTAMP")) , INSERTALLRECORDS , EXCEPTIONSONLY;;
Using the following key columns for target table GGS_ADMIN.EXCEPTIONS: LOGRBA, LOGPOSITION, COMMITTIMESTAMP.
2012-08-30 09:09:00 WARNING OGG-01154 SQL error 1403 mapping scr.order_items to scr.order_items OCI Error ORA-01403: no data found, SQL <DELETE FROM "scr"."order_items" WHERE "SUBSCRIBER_ID" = :b0>.
2012-08-30 09:09:00 WARNING OGG-00869 OCI Error ORA-00001: unique constraint (GGS_ADMIN.PK_EXCEPTIONS) violated (status = 1). INSERT INTO "GGS_ADMIN"."EXCEPTIONS" ("R
EP_NAME","TABLE_NAME","ERRNO","DBERRMSG","OPTYPE","ERRTYPE","LOGRBA","LOGPOSITION","COMMITTIMESTAMP") VALUES (:a0,:a1,:a2,:a3,:a4,:a5,:a6,:a7,:a8).
2012-08-30 09:09:00 WARNING OGG-01004 Aborted grouped transaction on 'GGS_ADMIN.EXCEPTIONS', Database error 1 (OCI Error ORA-00001: unique constraint (GGS_ADMIN.PK_EX
CEPTIONS) violated (status = 1). INSERT INTO "GGS_ADMIN"."EXCEPTIONS" ("REP_NAME","TABLE_NAME","ERRNO","DBERRMSG","OPTYPE","ERRTYPE","LOGRBA","LOGPOSITION","COMMITTIMES
TAMP") VALUES (:a0,:a1,:a2,:a3,:a4,:a5,:a6,:a7,:a8)).
2012-08-30 09:09:00 WARNING OGG-01003 Repositioning to rba 92383 in seqno 8.
2012-08-30 09:09:00 WARNING OGG-01154 SQL error 1403 mapping scr.order_items to scr.order_items OCI Error ORA-01403: no data found, SQL <DELETE FROM "scr"."order_items" WHERE "SUBSCRIBER_ID" = :b0>.
2012-08-30 09:09:00 WARNING OGG-01154 SQL error 1 mapping scr.order_items to GGS_ADMIN.EXCEPTIONS OCI Error ORA-00001: unique constraint (GGS_ADMIN.PK_EXCEPTIONS)
violated (status = 1). INSERT INTO "GGS_ADMIN"."EXCEPTIONS" ("REP_NAME","TABLE_NAME","ERRNO","DBERRMSG","OPTYPE","ERRTYPE","LOGRBA","LOGPOSITION","COMMITTIMESTAMP") VAL
UES (:a0,:a1,:a2,:a3,:a4,:a5,:a6,:a7,:a8).
2012-08-30 09:09:00 WARNING OGG-01003 Repositioning to rba 92383 in seqno 8.
When I am running command
select * from exceptions;
no row selected.
Please help. Why duplicat rows trying to insert in Exception table.Remove (disable) the constraint on the exceptions table and see if inserts will take place. Do you really need that primary key?
-
Hi everybody,
I want to develop an application and need exception handling.
I have a helper application that contains this classes:
MyADFPhaseListener extends ADFPhaseListener that return this: return new MyFacesPageLifecycle(),
MyErrorHandler extends DCErrorHandlerImpl,
MyFacesPageLifecycle extends FacesPageLifecycle that contain this methods:
prepareModel(LifecycleContext ctx) that set my errorhandler with this: ctx.getBindingContext().setErrorHandler(new MyErrorHandler(true));
and
reportErrors(PageLifecycleContext ctx){
DCBindingContainer bc = (DCBindingContainer)ctx.getBindingContainer();
if (bc != null) {
ArrayList<Exception> exceptions =new ArrayList<Exception>();
exceptions = bc.getExceptionsList();
if (exceptions != null) {
/*handle exceptions*/
My problem is here:
when throw an exception in my app like this: throw new JboException("Don't do that.", "101", null);
after create pagelifecycle and calling prepareModel(), reporterros() dose not call....!!!
why?
Edited by: 859070 on May 15, 2011 9:35 PMwhen click a button and call action of this button.
please note:
My helper application and main application are apart. I deploy helper application to jar file and use this jar file in main application.
Maybe exceptions don`t send to reportErrors() method in MyPageLifeCycle class, because i create a test class like this:
public class test {
public static void main(String[] args) throws SQLException {
ArrayList<Exception> exss = new ArrayList<Exception>();
exss.add(new JboException("A fatal exception is occurred",
"103", null));
exss.add(new NullPointerException());
exss.add(new SQLException());
MyFacesPageLifecycle efpl =new MyFacesPageLifecycle();
efpl.errorReporter(exss);
Body of errorReporter(ArrayList<Exception>) method is like reportErrors(PageLifecycleContext) just parameter is different.
public void errorReporter(ArrayList<Exception> excs) {
if (excs != null) {
for (Exception exception: excs) {
if(exception instanceof JboException){
System.out.println("JBOException is occurred here: "+exception.getMessage());
else if(exception instanceof SQLException){
System.out.println("SQLException is occurred here");
else if(exception instanceof NullPointerException){
System.out.println("NullPointerException is occurred here");
else{
and this handle exceptions list. My opinion is that exceptions between different applications(helper and main) are lost. is this correct? -
Exception Handling related problem
Can anybody tell me why it is not giving ArithmeticException.
package pckg1;
* @author anil_saini
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
import java.io.FileNotFoundException;
public class Average7 {
public static void main(String[] args) throws InterruptedException,FileNotFoundException {
try { // (1) System.out.println(printAverage(100, 0)); // (2)
} catch (ArithmeticException ae) { // (3)
Thread.sleep(1000);
ae.printStackTrace(); // (4)
System.out.println("Exception handled in " + // (5)
"main().");
finally {
System.out.println("Finally in main()."); // (6)
System.out.println("Exit main()."); // (7)
public static int printAverage(int totalSum, int totalNumber) {
int average=0;
try { // (8)
average = computeAverage(totalSum, totalNumber); // (9)
System.out.println("Average = " + // (10)
totalSum + " / " + totalNumber + " = " + average);
return average;
} catch (IllegalArgumentException iae) { // (11)
iae.printStackTrace(); // (12)
System.out.println("Exception handled in " + // (13)
"printAverage().");
} finally {
System.out.println("Finally in printAverage()."); // (14)
return average;
} // (15)
public static int computeAverage(int sum, int number) {
System.out.println("Computing average.");
if (number == 0) // (16)
throw new ArithmeticException("Integer division by 0");// (17)
return sum/number; // (18)
Output
=======================
Computing average.
Finally in printAverage().
0
Finally in main().
Exit main().Because return statements in finally blocks are evil!
int average = 0;
try
{ // (8)
average = computeAverage(totalSum, totalNumber); // (9)
System.out.println("Average = " + // (10)
totalSum + " / " + totalNumber + " = " + average);
return average;
catch (IllegalArgumentException iae)
{ // (11)
iae.printStackTrace(); // (12)
System.out.println("Exception handled in " + // (13)
"printAverage().");
throw new IllegalArgumentException();
finally
System.out.println("Finally in printAverage()."); // (14)
return average; // (15)
}You get an exception at (9), but finally is guaranteed to be executed, so the JVM executes it. Now you return in your finally block (15), and the JVM is left with the choice of executing your return statement or propagating the exception. Since, as said, finally is guaranteed to be executed, it returns and swallows the exception.
That's why IMHO return statements in finally blocks should not be allowed.
(Some compilers issue warnings)
If you move your return statement out of the finally block, it will work as you'd expect it. -
Use of raise in exception handling block
what is the use of raise in exception handling block for eg.
declare
a number;
b emp.empno%type;
begin
begin
SELECT empno INTO a FROM emp where 1=2;
exception
when others then
dbms_output.put_line('inner');
raise;
end;
exception
when no_data_found then
dbms_output.put_line('outer');
end;
output will be like below ..
inner
outer
PL/SQL procedure successfully completed.
my question is wht is the use of using raise in exception handing part, is there any specific reason we use in the development ????
Regards,
AAK.In the first block, you do not raise you user-defined exception WHEN_NO_DATA_FOUND, but the predefined one, which is raised to the WHEN OTHERS exception handler.
Consider:
SQL> declare
2 a number;
3 my_err exception;
4 no_data_found exception;
5 begin
6 begin
7 select 1 into a from dual where 1=2;
8 exception
9 when no_data_found then
10 dbms_output.put_line(' In system defined');
11 raise my_err;
12 end;
13 exception
14 when my_err then
15 dbms_output.put_line('In User Defined');
16 when others then
17 declare
18 v_sqlerrm varchar2(100);
19 begin
20 v_sqlerrm := sqlerrm;
21 dbms_output.put_line(' In when others '||sqlerrm);
22 end;
23 end;
24 /
In when others ORA-01403: no data found
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 declare
2 a number;
3 my_err exception;
4 --no_data_found exception;
5 begin
6 begin
7 select 1 into a from dual where 1=2;
8 exception
9 when no_data_found then
10 dbms_output.put_line(' In system defined');
11 raise my_err;
12 end;
13 exception
14 when my_err then
15 dbms_output.put_line('In User Defined');
16 when others then
17 declare
18 v_sqlerrm varchar2(100);
19 begin
20 v_sqlerrm := sqlerrm;
21 dbms_output.put_line(' In when others '||sqlerrm);
22 end;
23* end;
SQL> /
In system defined
In User Defined
PL/SQL procedure successfully completed.
SQL>Note that in the second block, I deleted the declaration of the user defined exception NO_DATA_FOUND.
This is taken from the documentation:
Redeclaring Predefined Exceptions
Remember, PL/SQL declares predefined exceptions globally in package STANDARD, so you need not declare them yourself. Redeclaring predefined exceptions is error prone because your local declaration overrides the global declaration. For example, if you declare an exception named invalid_number and then PL/SQL raises the predefined exception INVALID_NUMBER internally, a handler written for INVALID_NUMBER will not catch the internal exception. In such cases, you must use dot notation to specify the predefined exception, as follows:
EXCEPTION
WHEN invalid_number OR STANDARD.INVALID_NUMBER THEN
-- handle the error
END;You can read yourself :
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/errors.htm
Regards,
Gerd -
Can a include file exception crash an app server?
Hi,
Can somebody please help me with the answer to this question?
Question is: I have an include file in a jsp page. But this include
file is not present on the server and hence it is giving an
exception.This exception is being caught and a message is thrown on
the console.Now, will this exception 'crash' my app server anytime?
Also will the exception be thrown everytime a user tries to access the
jsp page? Please help.
Thanks,
"Shirin" <[email protected]> wrote in message
news:[email protected]..
> Hi,
>
> Can somebody please help me with the answer to this question?
> Question is: I have an include file in a jsp page. But this include
> file is not present on the server and hence it is giving an
> exception.This exception is being caught and a message is thrown on
> the console.Now, will this exception 'crash' my app server anytime?
No. It shouldn't crash the app server.
> Also will the exception be thrown everytime a user tries to access the
> jsp page? Please help.
Yes, until the file that is included exists or until the page handles the
exception.
Tom
-
Bundles can't contain multiple app packages error
Hi All,
I am building an universal windows application targeting to multiple platforms x86,x64 and ARM.
However when i build my project in TFS i get following exception
"D:\Builds\22\MDWindowsClient\MDWindowsClient_dev\src\MDWindowsClient\MDWindowsClient.Windows\MDWindowsClient.Windows.csproj" (default target) (2) ->
(_CreateBundle target) ->
MakeAppx : error : Error info: error 80080204: The package with file name "MDWindowsClient.Windows_1.0.0.9_x86_Debug.appx" and package full name "SMDWindowsClient_1.0.0.9_x64__8cggqpkfn886j" is not valid in the bundle because the bundle also contains the package with file name "SMDWindowsClient.Windows_1.0.0.9_x64_Debug.appx" and package full name "SMDWindowsClient_1.0.0.9_x64__8cggqpkfn886j" which applies to the same processor architecture. Bundles can't contain multiple app packages for the same processor architecture, or an architecture-neutral app package with any architecture-specific app package. [D:\Builds\22\SMDWindowsClient\SMDWindowsClient_dev\src\SMDWindowsClient\SMDWindowsClient.Windows\SMDWindowsClient.Windows.csproj]
MakeAppx : error : Bundle creation failed. [D:\Builds\22\MDWindowsClient\MDWindowsClient_dev\src\MDWindowsClient\MDWindowsClient.Windows\MDWindowsClient.Windows.csproj]
MakeAppx : error : 0x80080204 - The specified package format is not valid: The package manifest is not valid. [D:\Builds\22\MDWindowsClient\MDWindowsClient_dev\src\MDWindowsClient\MDWindowsClient.Windows\MDWindowsClient.Windows.csproj]
Already this kind of error was reported here https://social.msdn.microsoft.com/Forums/vstudio/en-US/ce255209-a94b-41c1-97f6-4659f5844ce3/how-to-create-a-windows-store-bundle-by-tfs-2013-build-system?forum=tfsbuildBut found no solution to this problem
Any help will be hugely appreciated.
Best Regards,
SauravHi Saurav,
Thanks for your post.
Your application is Windows Store application? And you can manually build(using MSBuild) your application on build agent machine successfully?
As this is a reproduced issue and posted to feedback site, but there’s no a solution in that old feedback and it be closed, so please resubmit this issue to Microsoft Connect Feedback portal at:
https://connect.microsoft.com/VisualStudio Microsoft engineers will evaluate them seriously.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
ADF Faces: Exception Handler activity ain't reraised
Hi there!
I'm using a Studio Edition Version 11.1.1.3.0 (Build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660).
I've done this:
1. created a bounded task flow flow1 and added to it:
1.1 a vew activity view1 (the default activity) - shows an inputText field for a db column, for which there is a constraint;
1.2 a method call activity method1 - calls commit;
1.3 a view activity view2 - has an ouputText depicting an attribute's value for the same collection as that of inputText in view1;
1.4 a view activity errorView (marked as an exception handler) - displays a localizedMessage from the currentViewPort;
1.5 created for the view activities page fragments (with necessary fields and buttons).
2. linked them as follows:
2.1 view1 -*-> method1 -*-> view2;
2.2 errorView -*-> view1.
3. in the default unbounded task flow created a view activity main, a page file for it, and dropped onto the latter the flow1 as a region;
4. launched the app (as the table contains some data, the view1 displays first row in a row set);
5. entered into the view1 's field a non-violating value;
6. pressed a button (which has just an action property set to move to the method1 ) - everything's fine, we get to the view2;
6. rerun the app;
7. entered incorrect value, pressed the button - flow goes, as expected, to the errorView, which informs us the exception's details (JBO-...);
8. on the errorView page fragment pressed a button - we are now on the view1 page again;
9. left the wrong (violating) value (or changed it to another incorrect value, doesn't matter) and pressed the button again;
10. wow, we reached the view2, but, I guess, we hadn't to. Why so?
One must note, that in clauses 7 and 9, after pressing the button, there apears a popup, which advises us about an ORA-... error, that is, in step 9 the ADF Faces does receive the exception, but why it doesn't reraise the errorView, that's the question.
Though, when I change the method1 so, that it calls a bean's method, which always throws an IllegalArgumentException, then everything works as should to - we get to the infinite loop - view1 -> method1 -> errorView -> view1.
Or, when I extract view2 from flow1, and instead of the former insert return activity with End Transaction set to commit, and then wrap (i.e call) flow1 from a newly created bounded task flow flow2, and in main 's page replace flow1 with flow2 region, the result is quite different. The aforesaid popup with ORA- error arises, until one enters a non-violating value. That is in this case everything is good, except, that control never flows into the errorView.
And there is one more thing to note yet. When I've, namely method1, been calling a bean with the ever exception throwing method, the Integrated WLS's log was silent, but when the method1 was calling commit, then in the log we can see this twice:
<Utils><buildFacesMessage> ADF: Adding the following JSF error message: ORA-02290: check constraint CHECK(THE_USER.THE_CONSTRAINT) violated
java.sql.SQLIntegrityConstraintViolationException: ORA-02290: check constraint CHECK(THE_USER.THE_CONSTRAINT) violated
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:85)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1035)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:953)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1224)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3386)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3467)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at oracle.jbo.server.OracleSQLBuilderImpl.doEntityDML(OracleSQLBuilderImpl.java:429)
at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:8044)
at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:6373)
at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3172)
at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:2980)
at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2018)
at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2277)
at oracle.adf.model.bc4j.DCJboDataControl.commitTransaction(DCJboDataControl.java:1577)
at oracle.adf.model.binding.DCDataControl.callCommitTransaction(DCDataControl.java:1404)
at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1427)
at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:2141)
at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:730)
at oracle.adf.controller.v2.lifecycle.PageLifecycleImpl.executeEvent(PageLifecycleImpl.java:394)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding._execute(FacesCtrlActionBinding.java:252)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding.execute(FacesCtrlActionBinding.java:210)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:157)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
at oracle.adf.controller.internal.util.ELInterfaceImpl.invokeMethod(ELInterfaceImpl.java:168)
at oracle.adfinternal.controller.activity.MethodCallActivityLogic.execute(MethodCallActivityLogic.java:161)
at oracle.adfinternal.controller.engine.ControlFlowEngine.executeActivity(ControlFlowEngine.java:989)
at oracle.adfinternal.controller.engine.ControlFlowEngine.doRouting(ControlFlowEngine.java:878)
at oracle.adfinternal.controller.engine.ControlFlowEngine.doRouting(ControlFlowEngine.java:777)
at oracle.adfinternal.controller.engine.ControlFlowEngine.routeFromActivity(ControlFlowEngine.java:551)
at oracle.adfinternal.controller.engine.ControlFlowEngine.performControlFlow(ControlFlowEngine.java:147)
at oracle.adfinternal.controller.application.NavigationHandlerImpl.handleAdfcNavigation(NavigationHandlerImpl.java:109)
at oracle.adfinternal.controller.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:78)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:130)
at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
at oracle.adf.view.rich.component.fragment.UIXRegion.broadcast(UIXRegion.java:148)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.broadcastEvents(LifecycleImpl.java:812)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:292)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:191)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:97)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:247)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:157)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:94)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:414)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:138)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:159)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:330)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)What I'm doing wrong? And how can I dismiss that popup, as it duplicates errorView and does not get messages from a custom message bundle?
Thanks in advance for any comments.
Yerzhan.Hi there!
I'm using a Studio Edition Version 11.1.1.3.0 (Build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660).
I've done this:
1. created a bounded task flow flow1 and added to it:
1.1 a vew activity view1 (the default activity) - shows an inputText field for a db column, for which there is a constraint;
1.2 a method call activity method1 - calls commit;
1.3 a view activity view2 - has an ouputText depicting an attribute's value for the same collection as that of inputText in view1;
1.4 a view activity errorView (marked as an exception handler) - displays a localizedMessage from the currentViewPort;
1.5 created for the view activities page fragments (with necessary fields and buttons).
2. linked them as follows:
2.1 view1 -*-> method1 -*-> view2;
2.2 errorView -*-> view1.
3. in the default unbounded task flow created a view activity main, a page file for it, and dropped onto the latter the flow1 as a region;
4. launched the app (as the table contains some data, the view1 displays first row in a row set);
5. entered into the view1 's field a non-violating value;
6. pressed a button (which has just an action property set to move to the method1 ) - everything's fine, we get to the view2;
6. rerun the app;
7. entered incorrect value, pressed the button - flow goes, as expected, to the errorView, which informs us the exception's details (JBO-...);
8. on the errorView page fragment pressed a button - we are now on the view1 page again;
9. left the wrong (violating) value (or changed it to another incorrect value, doesn't matter) and pressed the button again;
10. wow, we reached the view2, but, I guess, we hadn't to. Why so?
One must note, that in clauses 7 and 9, after pressing the button, there apears a popup, which advises us about an ORA-... error, that is, in step 9 the ADF Faces does receive the exception, but why it doesn't reraise the errorView, that's the question.
Though, when I change the method1 so, that it calls a bean's method, which always throws an IllegalArgumentException, then everything works as should to - we get to the infinite loop - view1 -> method1 -> errorView -> view1.
Or, when I extract view2 from flow1, and instead of the former insert return activity with End Transaction set to commit, and then wrap (i.e call) flow1 from a newly created bounded task flow flow2, and in main 's page replace flow1 with flow2 region, the result is quite different. The aforesaid popup with ORA- error arises, until one enters a non-violating value. That is in this case everything is good, except, that control never flows into the errorView.
And there is one more thing to note yet. When I've, namely method1, been calling a bean with the ever exception throwing method, the Integrated WLS's log was silent, but when the method1 was calling commit, then in the log we can see this twice:
<Utils><buildFacesMessage> ADF: Adding the following JSF error message: ORA-02290: check constraint CHECK(THE_USER.THE_CONSTRAINT) violated
java.sql.SQLIntegrityConstraintViolationException: ORA-02290: check constraint CHECK(THE_USER.THE_CONSTRAINT) violated
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:85)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1035)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:953)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1224)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3386)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3467)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at oracle.jbo.server.OracleSQLBuilderImpl.doEntityDML(OracleSQLBuilderImpl.java:429)
at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:8044)
at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:6373)
at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3172)
at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:2980)
at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2018)
at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2277)
at oracle.adf.model.bc4j.DCJboDataControl.commitTransaction(DCJboDataControl.java:1577)
at oracle.adf.model.binding.DCDataControl.callCommitTransaction(DCDataControl.java:1404)
at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1427)
at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:2141)
at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:730)
at oracle.adf.controller.v2.lifecycle.PageLifecycleImpl.executeEvent(PageLifecycleImpl.java:394)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding._execute(FacesCtrlActionBinding.java:252)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding.execute(FacesCtrlActionBinding.java:210)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:157)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
at oracle.adf.controller.internal.util.ELInterfaceImpl.invokeMethod(ELInterfaceImpl.java:168)
at oracle.adfinternal.controller.activity.MethodCallActivityLogic.execute(MethodCallActivityLogic.java:161)
at oracle.adfinternal.controller.engine.ControlFlowEngine.executeActivity(ControlFlowEngine.java:989)
at oracle.adfinternal.controller.engine.ControlFlowEngine.doRouting(ControlFlowEngine.java:878)
at oracle.adfinternal.controller.engine.ControlFlowEngine.doRouting(ControlFlowEngine.java:777)
at oracle.adfinternal.controller.engine.ControlFlowEngine.routeFromActivity(ControlFlowEngine.java:551)
at oracle.adfinternal.controller.engine.ControlFlowEngine.performControlFlow(ControlFlowEngine.java:147)
at oracle.adfinternal.controller.application.NavigationHandlerImpl.handleAdfcNavigation(NavigationHandlerImpl.java:109)
at oracle.adfinternal.controller.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:78)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:130)
at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
at oracle.adf.view.rich.component.fragment.UIXRegion.broadcast(UIXRegion.java:148)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.broadcastEvents(LifecycleImpl.java:812)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:292)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:191)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:97)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:247)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:157)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:94)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:414)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:138)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:159)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:330)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)What I'm doing wrong? And how can I dismiss that popup, as it duplicates errorView and does not get messages from a custom message bundle?
Thanks in advance for any comments.
Yerzhan. -
Hello. In my applications I usually have a try catch(Throwable) block surrounding all the top code (the code in main()) to log and report errors and exceptions that is not caught anywhere else, and to have my application exit in a controlled way. But I recently noticed that exceptions thrown in event handling (i.e. java.awt.EventDispatchThread.run) are not caught by the try catch block in main().
Are there any easy way to catch everything so my app can exit in a controlled way?
If this is not possible which exceptions are not propagated to main()? I would guess that it's exceptions thrown in other threads, is this correct? If so, do I have to surround all event handling by try catch(Throwable) to be safe?
I would like more information and guidelines about exception handling. Any book recommendations?
Help appreciated, thanks!You should never let exceptions propagate outside your event handling methods.
If you don't follow that rule, the java.awt.EventDispatchThread.run() method terminates and the Java Virtual Machine tries to print the stack trace to the terminal window (if there is one) and then exits, but not through your main() method.
So, try /catch all Exceptions inside your event handler methods:
// inside event handler method
try {
// handle event here
} catch (Throwable t) {
// handle errors and recover from errors here
// and either log error or if important display message to the user.
}There is no easy-lazy way to do exception handling by only having the try/catch block in main in this case.
Note : If any of the listeners throws an exception none of the following listeners is called. Since there is no guarantee of the order in which listeners are called you cannot be sure which ones are called first.
Maybe you are looking for
-
Windows vista doesn't recognize ipod touch
can anybody please help me! I'm trying to connect my ipod touch 2nd gen to my comp and windows vista doesn't install the software. I've tried to install the 32 bit & 64 bit versions of itunes but nothing works. On the 32 bit install, it goes all the
-
Issue in IPCC DB (db_cra)
I have an issue in IPCC DB (db_cra). In db_cra a table RTCSQSSummary is not updating its records.. I have configured Real Time Snapshot configurations. Table is working properly before but now records are not updatingf in it.. can anyone help me in t
-
Acrobat 9 pro, no preview possible in outlook 2007
I have acrobat 9 pro and microsoft office outlook 2007. Noy sure if it was possible before but nowadays whenever I try to preview a pdf document in outlook it gives the following error message: this file cannot be previewed because of an error with t
-
Is there a way or setting to delete one without deleteing the other? I have gone to RECENTS hit ALL and hit clear and it also clears all MISSED calls and vice versa. This is very frustrating. If anyone knows of a solution this would be great.
-
GUI_UPLOAD data problem
we are uploading .DAT file in following program, after uploading the data into sap system, we are not able to see the complete data first row last two three fields are missing, the total field values length is 331 character, even if i given the 5000