Normally in java or C# , I would use a following construct when try and catch errors.
Bad Exception Handling in C# and Java
try
{
// do something
}
catch(Exception ex)
{
}
Good Exception Handling in Java and C#
try
{
}
catch(ArgumentException ex)
{
log(ex);
// java throw
throw ex;
// in C#, throw only, is better since it keeps stack trace
throw;
}
catch(Exception ex)
{
// this is catch ALL others block
log(ex);
// java throw
throw ex;
// in C#, throw only, is better since it keeps stack trace
throw;
}
In C# and java , I would use logging libraries.
java : log4j,
see others
https://stackoverflow.com/questions/3042450/what-log4j-alternative-logging-libraries-are-available
.Net : log4net, Nlog etc
In PL/SQL
Bad Exception Handling
BEGIN
-- Do Something
EXCEPTION -- exception handlers begin
WHEN ZERO_DIVIDE THEN
null;
WHEN OTHERS THEN
null;
END;
Good Exception Handling
BEGIN
-- Do Something
EXCEPTION -- exception handlers begin
WHEN ZERO_DIVIDE THEN
LOG
RAISE
WHEN OTHERS THEN
LOG
RAISE
END;
a simple google search brings log4plsql package : http://log4plsql.sourceforge.net/
- Are there any other libraries?
- Are they prevalent in PL/SQL programming?
Oracle Documentation for Error Handling does not give hints about logging.
It gives following sentence and uses dbms_output.put_line for logging:
"Sometimes, you want to reraise an exception, that is, handle it
locally, then pass it to an enclosing block. For example, you might
want to roll back a transaction in the current block, then log the
error in an enclosing block."
Best Answer
Prevalent? No. It's not uncommon, however, to write a procedure like so:
Then you can add calls to
write_to_log
where needed throughout the code.