11 Replies Latest reply: Aug 4, 2013 1:29 PM by 9423755 RSS

    In which of the following sections of a PL/SQL block is a user-defined exception raised?

    9423755

      Hi,

      A (somewhat elementary) question:

       

      In which of the following sections of a PL/SQL block is a user-defined exception raised?

       

      a) Exception section

      b) Declarative section

      c) Error handling section

      d) Executable section

       

       

      I'd be interested to hear people's answers.

       

      Thanks.

        • 2. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
          Etbin

          From PL/SQL: Building with Blocks


          PL/SQL is a block-structured language. A PL/SQL block is defined by the keywords DECLARE, BEGIN, EXCEPTION, and END, which break up the block into three sections:


               Declarative: statements that declare variables, constants, and other code elements, which can then be used within that block

               Executable: statements that are run when the block is executed

               Exception handling: a specially structured section you can use to “catch,” or trap, any exceptions that are raised when the executable section runs

          Only the executable section is required. You don’t have to declare anything in a block, and you don’t have to trap exceptions raised in that block.

          The answer should be: In the only required one.

          Regards

          Etbin

          • 3. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
            Solomon Yakobson

            As Etbin already noted, there are only 3 sections and user-defined exception can be raised in any of them. User-defined exception raised in declarative section example:

             

            declare

                year_zero exception;

                pragma exception_init(year_zero,-01841);

            begin

                declare

                    v_dt date := to_date(1721420,'j');

                begin

                    null;

                end;

              exception

                when year_zero

                  then

                    dbms_output.put_line('Year 0!');

            end;

            /

            Year 0!

            PL/SQL procedure successfully completed.

            SQL>

             

            User-defined exception raised in executable section example:

             

            declare

                year_zero exception;

                pragma exception_init(year_zero,-01841);

                v_dt date;

            begin

                v_dt := to_date(1721420,'j');

              exception

                when year_zero

                  then

                    dbms_output.put_line('Year 0!');

            end;

            /

            Year 0!

            PL/SQL procedure successfully completed.

            SQL>

             

            User-defined exception raised in exception handling section example:

             

            declare

                year_zero exception;

                pragma exception_init(year_zero,-01841);

                v_dt date;

            begin

                declare

                    v_num number;

                begin

                    v_num := 1 / 0;

                  exception

                    when others

                      then

                        v_dt := to_date(1721420,'j');

                end;

              exception

                when year_zero

                  then

                    dbms_output.put_line('Year 0!');

            end;

            /

            Year 0!

            PL/SQL procedure successfully completed.

            SQL>

             

            SY.

            • 4. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
              9423755

              Thanks for your responses.

               

              I think you're right Solomon, but given the constraint, which must be to choose a single answer (my apologies for not stating that), I chose (a).

              The answer that they (UCertify) give is indeed (a) - the execution section. I could swear blind when I answered this question the first time first thing this morning (I had to abort the little test part-way through and have only just now redone it) I answered (a) and they gave a different answer, much to my chagrin, hence my submitting this question.

              An exception may be raised by the _system_ anywhere, as you say.

              An exception may only explicitly be raised by the programmer as far as I'm aware in the execution section or the exception section.

              • 5. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
                Etbin

                In this type of questions (even if you know a single answer is expected) there's usually a terrible lack of context (in this case for example: can blocks within the block be considered or not, does raised imply using the raise command, ...)

                I still remember my university Programming Class professor Zakrajšek saying: If you're not top prepaired, you'd usually be better off choosing answers at random.

                In the same period my sister told me at Grammar School a fellow returned a solved English Language test even before the professor had a chance to distribute it.

                He simply checked all (a)s and left the class.

                The professor was forced to give him a rather high grade (there were no PCs at the time so the tests were typed on a typewriter and there was a great tendency to type the correct answers near the beginning)


                Regards


                Etbin

                • 6. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
                  9423755

                  I agree Etbin. These questions have a tendency to be vaguely phrased, leaving too much room for ambiguity.

                  Pretty sure there were similar questions on my 1z0-144 exam, some of which were couched in shockingly poor English.  Of course, you can never complain, because once it's done, you can't remember the questions - which were poorly phrased, which were ambiguous, etc. You just have to "hope" and "pray" that you resolved (or disregarded) ambiguities in the "right" way.

                   

                  E.g. I just came across another one: Where can you call user-defined functions in SQL?

                  Answer: ... SELECT list, WHERE, GROUP BY, ORDER BY.

                  Incorrect answer: FROM clause.

                   

                  Well, Oracle themselves don't specify that you can call a user-defined function in the FROM clause, but they don't say that you can't.  And we all know that you can call a table function in the FROM clause by wrapping it in the TABLE() function.

                  So what am I supposed to answer if the question comes up? 

                  • 7. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
                    Etbin

                    ...

                    Laugh about it, shout about it when you've got to choose

                    Every way you look at it you lose

                    ...

                     

                    Read more: SIMON AND GARFUNKEL - MRS ROBINSON LYRICS


                    Regards


                    Etbin

                    • 8. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
                      Solomon Yakobson

                      Jason_942375 wrote:

                       

                      I chose (a).

                       

                      Where did you get this question? As Etbin already stated there is no such thing as "Exception section". Now assuming you have to choose 1 answer, I'd say d) Executable section. Assumptions are as follows. Most likely question is about a single (no inner no outer blocks) PL/SQL block and therefore about user-defined exception declared in that block. So PL/SQL block declares a user-defined exception. If exception associated with same error code as in user-defined exception is raised in declarative section it is handled by calling block where our PL/SQL block user-defined exception is out of scope. Same way, if exception associated with same error code as in user-defined exception is raised in error handling section it is handled by calling block where our user-defined exception is out of scope. So the only section wher user-defined exception declared in PL/SQL block can de raised is executable section.


                      SY.

                      • 9. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
                        Etbin

                        A less technical way to look at the question could be:

                        A user-defined exception is used when something is expected to occurr, something that must not be ignored, something Oracle isn't aware of.

                        So (by the nature of things) the user is required to explicitly raise the exception (s)he has declared during the code execution.

                        When in the declaration part, nothing has happened yet.

                        When in the exception part, the exception has been raised already.

                         

                        Regards

                         

                        Etbin

                        • 10. Re: In which of the following sections of a PL/SQL block is a user-defined exception raised?
                          9423755

                          The question is from the uCertify exam prep for 146.