Comments (2)
from SonarQube:
"DBMS_UTILITY.FORMAT_ERROR_STACK" and "FORMAT_ERROR_BACKTRACE" should be used together
Since Oracle 10g, DBMS_UTILITY.FORMAT_ERROR_BACKTRACE is available to get an exception's stack trace, i.e. files and lines that lead up to the exception. When combined with DBMS_UTILITY.FORMAT_ERROR_STACK, which contains the exception error code and message, developers are able quickly identify defects.
This rule verifies that whenever either is used in an exception handler, the other is used as well.
Noncompliant Code Example
BEGIN
RAISE_APPLICATION_ERROR(-20000, 'This is an error example');
EXCEPTION
WHEN OTHERS THEN -- Noncompliant; only FORMAT_ERROR_STACK is used
DBMS_OUTPUT.PUT(DBMS_UTILITY.FORMAT_ERROR_STACK); -- "ORA-20000: This is an error example"
DBMS_OUTPUT.PUT_LINE('');
END;
/
Compliant Solution
BEGIN
RAISE_APPLICATION_ERROR(-20000, 'This is an error example');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT(DBMS_UTILITY.FORMAT_ERROR_STACK); -- "ORA-20000: This is an error example"
DBMS_OUTPUT.PUT(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE); -- "ORA-06512: at line 2"
DBMS_OUTPUT.PUT_LINE('');
END;
/
from plsql-and-sql-coding-guidelines.
Sound reasonable. However, consider the following exception block:
EXCEPTION
WHEN OTHERS THEN
-- handle backtrace error stack
l_backtrace := dbms_utility.format_error_backtrace;
-- log incident and stop logging
...logging.process_stop(
i_process_id => l_process_id,
i_incident_description => SQLERRM || chr(10) || l_backtrace
);
-- raise exception after logging
RAISE;
SQLERRM
was used Instead of dbms_utility.format_error_stack
in this case. That's ok from my point of view. The sequence of the calls should not matter. Never. It really depends how the logging system works.
Using format_error_backtrace
together with SQLERR
, SQLERRM
or format_error_stack
makes sense.
from plsql-and-sql-coding-guidelines.
Related Issues (20)
- G-3120: eliminate violations
- G-9030: eliminate violations HOT 1
- G-1040: add NOSONAR Hint in G-7250
- G-7110: eliminate violations
- G-3210: eliminate violations
- G-4320: eliminate violations
- Various guidelines: eliminate violations (2-4 issues per guideline) HOT 1
- New rule: Always specify column aliases instead of positional references in GROUP BY clauses.
- CASE / WHEN is indentend backwards HOT 2
- Fix catagorization of guideline severties.
- New rule: Always specify column names instead of expressions in GROUP BY clauses.
- The tools do not work from a Windows host with git-bash HOT 1
- Use 3 literals in the bad example of G-1050
- Simplify G-1050 and related examples
- Include column alias in G-3182 HOT 1
- Fix revision history in about page
- Highlight the lines that violate a guideline in the bad examples (and the fixed lines in the good examples)
- G-8310 value_error good_example HOT 3
- New rule: Avoid autonomous transactions
- New rule: Avoid using a FOR LOOP for a query that should return not more than one row HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plsql-and-sql-coding-guidelines.