A User defined exception can help enforce business rules In
A User defined exception can help enforce business rules. In order to implement a user define exception:
In the declaration section, one needs to specify a name for the exception which must have the EXCEPTION data type
In the Begin/End section, there must be a RAISE exception-name statement to trigger the exception
When an exception is raised, control is transferred to the EXCEPTION section
True
False
| A User defined exception can help enforce business rules. In order to implement a user define exception: In the declaration section, one needs to specify a name for the exception which must have the EXCEPTION data type In the Begin/End section, there must be a RAISE exception-name statement to trigger the exception When an exception is raised, control is transferred to the EXCEPTION section |
Solution
1. An exception is raised automatically whenever current running PL/SQL code violates an Oracle rule or it might be because of system dependent limitations.
2. PL/SQL provides some predefined exceptions that are raised automatically.
Examples:
TOO_MANY_ROWS -> This kind of exceptions gets raised when SELECT statement returns more than one row.
3. However, PL/SQL provides a flexibility to users for defining exceptions by their own.
4. There are three sections to be followed while defining user defined exceptions.
1. Exceptions need to be declared in declarative part
Example: my_exception EXCEPTION;
EXCEPTION is the data type and my_exception is the exception name
2. Using RAISE statement, exception can be triggered with in the Begin/End section.
Example: RAISE my_exception;
3. Once the exception is raised, it is handled by corresponding Exception handler in EXCEPTION section.
Example:
WHEN my_exception THEN
-- handle the error
5. Sample PL/SQL block:
DECLARE
productCount INTEGER := -2;
product_out_of_stock EXCEPTION;
BEGIN
IF productCount <= 0 THEN
RAISE product_out_of_stock; -- Raising user-defined exception
END IF;
EXCEPTION
WHEN product_out_of_stock THEN
dbms_output.put.line(\' Alert!!! Product out of stock... \');;
END;
--------------------------------------------------------------------------------------------------------------------
Hence the given statement is TRUE

