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









share|improve this question


























    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









    share|improve this question
























      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









      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 16:47









      eztam

      1,11031639




      1,11031639
























          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.






          share|improve this answer




























            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.






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              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

























              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.






              share|improve this answer

























                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.






                share|improve this answer























                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 at 18:46









                  alexgibbs

                  1,5732913




                  1,5732913
























                      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.






                      share|improve this answer

























                        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.






                        share|improve this answer























                          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.






                          share|improve this answer












                          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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 19 at 19:23









                          Namandeep_Kaur

                          9017




                          9017






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Feedback on college project

                              Futebolista

                              Albești (Vaslui)