Home
DBMS_UTILITY.FORMAT_ERROR_STACK and FORMAT_ERROR_BACKTRACE should be used together
Description
The DBMS_UTILITY.FORMAT_ERROR_STACK and FORMAT_ERROR_BACKTRACE should be used together in order to get a comprehensive view of the error stack and backtrace. The FORMAT_ERROR_STACK function will return the error stack as a single string, while the FORMAT_ERROR_BACKTRACE function will return the backtrace as a single string. When used together, these functions will provide a comprehensive view of the error stack and backtrace, allowing for easier debugging and troubleshooting.
Key Benefits
- Improved Troubleshooting: DBMS_UTILITY.FORMAT_ERROR_STACK and FORMAT_ERROR_BACKTRACE should be used together to provide a more detailed and accurate error stack trace, which can help in troubleshooting and resolving issues quickly. :
- More Comprehensive Error Analysis: By combining the two functions, it is possible to analyze more detailed information about the error, such as which line of code caused the error and the exact error message. :
- Better Debugging Capabilities: The combination of the two functions allows for better debugging capabilities, as it is possible to pinpoint the exact source of the error and examine the code to determine the cause. :
Non-compliant Code Example
BEGIN
FOR i IN 1 .. CUSTOMER_TABLE.COUNT
LOOP
IF CUSTOMER_TABLE(i) IS NOT NULL THEN
DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
END IF;
END LOOP;
EXCEPTION
WHEN ERRORS THEN --Non compliant code (Only DBMS_UTILITY.FORMAT_ERROR_STACK is used)
Log_Errors ( 'Error Log...' || Chr(10) ||
DBMS_UTILITY.FORMAT_ERROR_STACK() );
DBMS_OUTPUT.PUT_LINE ( '----------' );
END CUSTOMER_TABLE_ITERATION;
Compliant Code Example
BEGIN
FOR i IN 1 .. CUSTOMER_TABLE.COUNT
LOOP
IF CUSTOMER_TABLE(i) IS NOT NULL THEN
DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
END IF;
END LOOP;
EXCEPTION
WHEN ERRORS THEN --Compliant code (FORMAT_ERROR_STACK and FORMAT_ERROR_BACKTRACE are used together)
Log_Errors ( 'Error Log...' || Chr(10) ||
DBMS_UTILITY.FORMAT_ERROR_STACK() );
Log_Errors ( 'Error Log...' || Chr(10) ||
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE() );
DBMS_OUTPUT.PUT_LINE ( '----------' );
END CUSTOMER_TABLE_ITERATION;