0
0
PostgreSQLquery~10 mins

Exception handling (BEGIN-EXCEPTION-END) in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a block for exception handling in PostgreSQL.

PostgreSQL
BEGIN[1]
Drag options to blanks, or click blank then click option'
ADECLARE
BEND
CBEGIN
DEXCEPTION
Attempts:
3 left
💡 Hint
Common Mistakes
Using EXCEPTION to start the block instead of BEGIN.
Using END to start the block.
Using DECLARE to start the block.
2fill in blank
medium

Complete the code to catch exceptions in a PostgreSQL block.

PostgreSQL
BEGIN
  -- some code
[1]
  WHEN others THEN
    RAISE NOTICE 'Error occurred';
END;
Drag options to blanks, or click blank then click option'
AEXCEPTION
BIF
CDECLARE
DTRY
Attempts:
3 left
💡 Hint
Common Mistakes
Using TRY instead of EXCEPTION.
Using IF instead of EXCEPTION.
Using DECLARE instead of EXCEPTION.
3fill in blank
hard

Fix the error in the exception block keyword.

PostgreSQL
BEGIN
  -- some code
[1]
  WHEN division_by_zero THEN
    RAISE NOTICE 'Cannot divide by zero';
END;
Drag options to blanks, or click blank then click option'
AEXCEPTION
BEXCEPT
CCATCH
DHANDLE
Attempts:
3 left
💡 Hint
Common Mistakes
Using EXCEPT instead of EXCEPTION.
Using CATCH or HANDLE which are not valid in PostgreSQL.
4fill in blank
hard

Fill both blanks to complete the exception block that handles a unique violation error.

PostgreSQL
BEGIN
  INSERT INTO users(username) VALUES('admin');
[1]
  WHEN unique_violation THEN
    RAISE NOTICE 'Username already exists';
[2]
END;
Drag options to blanks, or click blank then click option'
AEXCEPTION
BWHEN
CEND
DDECLARE
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHEN to start the exception block instead of EXCEPTION.
Using DECLARE instead of EXCEPTION.
Forgetting to close the block with END.
5fill in blank
hard

Fill all three blanks to complete the exception block that handles division by zero and others.

PostgreSQL
BEGIN
  PERFORM 10 / [1];
[2]
  WHEN division_by_zero THEN
    RAISE NOTICE 'Division by zero error';
  WHEN others THEN
    RAISE NOTICE 'Some other error';
[3]
END;
Drag options to blanks, or click blank then click option'
A0
BEXCEPTION
CEND
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 as divisor to cause division by zero error.
Using TRY or CATCH instead of EXCEPTION.
Forgetting to close the block with END.