Are following statements executed in any case if the first one throws an exception?
up vote
0
down vote
favorite
When an exception happens at the first select statement. Will the second select statement and the function then be executed in any case? Or will all following statements be skipped ?
BEGIN
SELECT ...
SELECT ...
procedure_that_performs_select();
EXCEPTION
WHEN NO_DATA_FOUND THEN ...
END
oracle exception plsql
add a comment |
up vote
0
down vote
favorite
When an exception happens at the first select statement. Will the second select statement and the function then be executed in any case? Or will all following statements be skipped ?
BEGIN
SELECT ...
SELECT ...
procedure_that_performs_select();
EXCEPTION
WHEN NO_DATA_FOUND THEN ...
END
oracle exception plsql
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When an exception happens at the first select statement. Will the second select statement and the function then be executed in any case? Or will all following statements be skipped ?
BEGIN
SELECT ...
SELECT ...
procedure_that_performs_select();
EXCEPTION
WHEN NO_DATA_FOUND THEN ...
END
oracle exception plsql
When an exception happens at the first select statement. Will the second select statement and the function then be executed in any case? Or will all following statements be skipped ?
BEGIN
SELECT ...
SELECT ...
procedure_that_performs_select();
EXCEPTION
WHEN NO_DATA_FOUND THEN ...
END
oracle exception plsql
oracle exception plsql
asked Nov 19 at 16:47
eztam
1,11031639
1,11031639
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
In PLSQL, the occurrence of an exception stops program exectuion at the point of the exception and jumps to the EXCEPTION block, if any, for handling, else raises the exception to the client.
You can see this behavior in a test block.
Here we will print before and after the exception, and can observe the next statement after the exception does not get printed:
BEGIN
DBMS_OUTPUT.PUT_LINE('About to throw an exception');
RAISE_APPLICATION_ERROR(-20001,'Exception');
DBMS_OUTPUT.PUT_LINE('Done throwing exception');
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Handling the exception');
END;
/
Result:
About to throw an exception
Handling the exception
Note: in the example you provided, the EXCEPTION block only handles NO DATA FOUND exceptions, so other types of exceptions will be raised instead of running through the exception handler. But in any case, things will stop processing at the point of the exception.
add a comment |
up vote
1
down vote
Once the control goes to an exception block, it doesn't go back to the begin or declare section of the pl/sql block.
Following the same, if there is an error in your first select statement, the exception block will be executed and the respective handler would be used. In case, you have neither mentioned the respective handler nor a WHEN OTHERS, the control will go to the calling environment (either any procedure or interface/ IDE).
In case, you still wish to run the second select statement, you could write another pl/sql block in exception handler.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
In PLSQL, the occurrence of an exception stops program exectuion at the point of the exception and jumps to the EXCEPTION block, if any, for handling, else raises the exception to the client.
You can see this behavior in a test block.
Here we will print before and after the exception, and can observe the next statement after the exception does not get printed:
BEGIN
DBMS_OUTPUT.PUT_LINE('About to throw an exception');
RAISE_APPLICATION_ERROR(-20001,'Exception');
DBMS_OUTPUT.PUT_LINE('Done throwing exception');
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Handling the exception');
END;
/
Result:
About to throw an exception
Handling the exception
Note: in the example you provided, the EXCEPTION block only handles NO DATA FOUND exceptions, so other types of exceptions will be raised instead of running through the exception handler. But in any case, things will stop processing at the point of the exception.
add a comment |
up vote
2
down vote
accepted
In PLSQL, the occurrence of an exception stops program exectuion at the point of the exception and jumps to the EXCEPTION block, if any, for handling, else raises the exception to the client.
You can see this behavior in a test block.
Here we will print before and after the exception, and can observe the next statement after the exception does not get printed:
BEGIN
DBMS_OUTPUT.PUT_LINE('About to throw an exception');
RAISE_APPLICATION_ERROR(-20001,'Exception');
DBMS_OUTPUT.PUT_LINE('Done throwing exception');
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Handling the exception');
END;
/
Result:
About to throw an exception
Handling the exception
Note: in the example you provided, the EXCEPTION block only handles NO DATA FOUND exceptions, so other types of exceptions will be raised instead of running through the exception handler. But in any case, things will stop processing at the point of the exception.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
In PLSQL, the occurrence of an exception stops program exectuion at the point of the exception and jumps to the EXCEPTION block, if any, for handling, else raises the exception to the client.
You can see this behavior in a test block.
Here we will print before and after the exception, and can observe the next statement after the exception does not get printed:
BEGIN
DBMS_OUTPUT.PUT_LINE('About to throw an exception');
RAISE_APPLICATION_ERROR(-20001,'Exception');
DBMS_OUTPUT.PUT_LINE('Done throwing exception');
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Handling the exception');
END;
/
Result:
About to throw an exception
Handling the exception
Note: in the example you provided, the EXCEPTION block only handles NO DATA FOUND exceptions, so other types of exceptions will be raised instead of running through the exception handler. But in any case, things will stop processing at the point of the exception.
In PLSQL, the occurrence of an exception stops program exectuion at the point of the exception and jumps to the EXCEPTION block, if any, for handling, else raises the exception to the client.
You can see this behavior in a test block.
Here we will print before and after the exception, and can observe the next statement after the exception does not get printed:
BEGIN
DBMS_OUTPUT.PUT_LINE('About to throw an exception');
RAISE_APPLICATION_ERROR(-20001,'Exception');
DBMS_OUTPUT.PUT_LINE('Done throwing exception');
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Handling the exception');
END;
/
Result:
About to throw an exception
Handling the exception
Note: in the example you provided, the EXCEPTION block only handles NO DATA FOUND exceptions, so other types of exceptions will be raised instead of running through the exception handler. But in any case, things will stop processing at the point of the exception.
answered Nov 19 at 18:46
alexgibbs
1,5732913
1,5732913
add a comment |
add a comment |
up vote
1
down vote
Once the control goes to an exception block, it doesn't go back to the begin or declare section of the pl/sql block.
Following the same, if there is an error in your first select statement, the exception block will be executed and the respective handler would be used. In case, you have neither mentioned the respective handler nor a WHEN OTHERS, the control will go to the calling environment (either any procedure or interface/ IDE).
In case, you still wish to run the second select statement, you could write another pl/sql block in exception handler.
add a comment |
up vote
1
down vote
Once the control goes to an exception block, it doesn't go back to the begin or declare section of the pl/sql block.
Following the same, if there is an error in your first select statement, the exception block will be executed and the respective handler would be used. In case, you have neither mentioned the respective handler nor a WHEN OTHERS, the control will go to the calling environment (either any procedure or interface/ IDE).
In case, you still wish to run the second select statement, you could write another pl/sql block in exception handler.
add a comment |
up vote
1
down vote
up vote
1
down vote
Once the control goes to an exception block, it doesn't go back to the begin or declare section of the pl/sql block.
Following the same, if there is an error in your first select statement, the exception block will be executed and the respective handler would be used. In case, you have neither mentioned the respective handler nor a WHEN OTHERS, the control will go to the calling environment (either any procedure or interface/ IDE).
In case, you still wish to run the second select statement, you could write another pl/sql block in exception handler.
Once the control goes to an exception block, it doesn't go back to the begin or declare section of the pl/sql block.
Following the same, if there is an error in your first select statement, the exception block will be executed and the respective handler would be used. In case, you have neither mentioned the respective handler nor a WHEN OTHERS, the control will go to the calling environment (either any procedure or interface/ IDE).
In case, you still wish to run the second select statement, you could write another pl/sql block in exception handler.
answered Nov 19 at 19:23
Namandeep_Kaur
9017
9017
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379202%2fare-following-statements-executed-in-any-case-if-the-first-one-throws-an-excepti%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown