Bird
0
0

Given this block:

medium📝 query result Q5 of 15
PostgreSQL - Advanced PL/pgSQL
Given this block:
DO $$
BEGIN
  PERFORM 10 / 0;
EXCEPTION
  WHEN division_by_zero THEN
    RAISE NOTICE 'Handled division by zero error';
  WHEN OTHERS THEN
    RAISE NOTICE 'Other error caught';
END $$;

What will be the output?
ANOTICE: Handled division by zero error
BNOTICE: Other error caught
CERROR: division by zero
DNo output, block completes silently
Step-by-Step Solution
Solution:
  1. Step 1: Identify the error

    The expression 10 / 0 causes a division_by_zero error.
  2. Step 2: Check exception handlers

    There is a specific handler for division_by_zero and a generic WHEN OTHERS handler.
  3. Step 3: Determine which handler executes

    The division_by_zero handler matches and runs first.
  4. Final Answer:

    NOTICE: Handled division by zero error -> Option A
  5. Quick Check:

    Specific exception handlers take precedence over WHEN OTHERS [OK]
Quick Trick: Specific exceptions handled before WHEN OTHERS [OK]
Common Mistakes:
  • Expecting the generic WHEN OTHERS handler to run first
  • Assuming the error will propagate without notice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes