7. Compile-time warnings help avoid "WHEN OTHERS THEN NULL".

Опубликовано: 29 Март 2016
на канале: Practically Perfect PL/SQL with Steven Feuerstein
2,502
9

One of Tom Kyte's favorite pet peeves, the following exception sections "swallow up" errors.

EXCEPTION
WHEN OTHERS
THEN
NULL;

EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE (SQLERRM);

In fact, any exception handler that does not re-raise the same exception or another, runs the risk of hiding errors from the calling subprogram, your users, and yourself as you debug your code.

Generally, you should log the error, then re-raise it.

There are certainly some cases in which this advice does not hold (for example: a function that fetches a single row for a primary key. If there is no row for the key, it's not an application error, so just return NULL). In those cases, include a comment so that the person maintaining your code in the distant future knows that you weren't simply ignoring the Wisdom of the Kyte. Example:

EXCEPTION
WHEN OTHERS
THEN
/* No company or this ID, let calling subprogram decide what to do */
RETURN NULL;

One way to avoid this problem is to turn on compile-time warnings. Then when your program unit is compiled, you will be warned if the compiler has identified an exception handler that does not contain a RAISE statement or a call to RAISE_APPLICATION_ERROR.

Related blog post: http://stevenfeuersteinonplsql.blogsp...

========================================
Practically Perfect PL/SQL with Steven Feuerstein

Copyright © 2015 Oracle and/or its affiliates. Oracle is a registered trademark of Oracle and/or its affiliates. All rights reserved. Other names may be registered trademarks of their respective owners. Oracle disclaims any warranties or representations as to the accuracy or completeness of this recording, demonstration, and/or written materials (the “Materials”). The Materials are provided “as is” without any warranty of any kind, either express or implied, including without limitation warranties or merchantability, fitness for a particular purpose, and non-infringement.


Смотрите видео 7. Compile-time warnings help avoid "WHEN OTHERS THEN NULL". онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Practically Perfect PL/SQL with Steven Feuerstein 29 Март 2016, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2,502 раз и оно понравилось 9 людям.