《Oracle PL/SQL开发指南》学习笔记21——错误管理(Error Management)(章节回顾、测试)

异常管理可以让程序更为健壮,不可不察也。

异常类型和作用域(Exception Types and Scope)

Review Section
This section has described the following points about exception types and scope:
1. Compile-time errors typically are typing errors, and they occur during the parsing of PL/SQL programs. They can include errors with lexical units, and they can be the misspelling of or misuse of identifiers as variable names. The misspelled or misused identifiers are typically keywords or reserved words in SQL or PL/SQL languages.
2.  A compile-time error may point to one of three locations: the first character of the next line, when the error occurs as the last element of the preceding line; a character immediately following the error on the same line; or the beginning of the declaration block, for a nonparsing error.
3. Runtime errors occur after the program is parsed and literal values are assigned to local variables.
4. Runtime errors can occur in the declaration, execution, or exception blocks.
5. Runtime errors thrown in the execution block are handled by the local exception block.
6. Runtime errors thrown in the declaration or exception block can't be handled by local exception blocks.

 

异常管理内置函数(Exception Management Built-in Functions)

Review Section
This section has described the following points about user-defined exceptions:
1. You can declare user-defined exceptions in any declaration block.
2. You can declare a PRAGMA, which is a precompiler instruction or compiler directive that maps an error code to a user-defined exception.
3. The RAISE statement lets you throw an exception.
4. A RAISE statement with an Oracle error code lets the SQLERRM function return an error code and message.
5. A RAISE statement with a user-defined error code lets the SQLERRM function return only an error code because there’s no external message file that supports the error code.
6. The RAISE_APPLICATION_ERROR function lets you raise a dynamic error code and message with or without an exception stack.

 

异常堆栈函数(Exception Stack Functions)

Review Section
This section has described the following points about user-defined exceptions:
1. Oracle provides you with the utl_call_stack package to manage exception stacks.
2. The dbms_utility package provides you with the format_error_backtrace function, which generates a stack trace.
3. The utl_call_stack package keeps tabs of the execution stack separately from the error stack.
4.  It's possible to parse and convert the text output from the format_error_backtrace function to HTML output.

 

测验(Mastery Check)


The mastery check is a series of true-or-false and multiple-choice questions that let you confirm
how well you understand the material in the chapter. You may check Appendix I for answers to
these questions.

True or False:
1. Oracle PL/SQL programming requires you to understand how to capture and analyze both compile-time errors and runtime errors.
True. You need to understand how to analyze and capture compile-time errors to make sure you can compile your code. You need to understand how to analyze and trap runtime errors.
2. A compile-time error may occur when you try to run an anonymous block program.
True. Compile-time means the same thing for both anonymous block and named block programs. It’s the time where the program is parsed and compiled into p-code. Any failure during parsing is a compile time error.
3. A runtime error may occur when you try to compile a stored procedure.
False. A runtime error can only occur after you’ve successfully compiled a stored procedure.
A compile-time error can occur when you try to create or replace a procedure.
4. A runtime error may occur when you call a stored procedure.
True. A runtime error may occur when you call a stored procedure.
5. A THROW command raises a runtime exception.
False. A RAISE statement or RAISE_APPLICATION_ERROR function call raises a runtime exception. A THROW command raises an exception in Java, not in PL/SQL.
6. It’s possible to declare a user-defined exception variable with the same error code as a predefined exception.
True. It’s possible to declare a user-defined exception variable with the same error code as a predefined exception. You’ll want to do so when you don’t have a predefined exception to handle the error code.

7. A PRAGMA is a precompiler instruction or compiler directive.
True. A PRAGMA is a compiler directive. Alternatively, a PRAGMA is also frequently referred to as a precompiler instruction.
8. An EXCEPTION_INIT complier directive lets you map a user-defined EXCEPTION variable to a message.
False. While an EXCEPTION_INIT is a compiler directive, it maps a user-defined EXCEPTION variable and an error code number.
9. A RAISE_APPLICATION_ERROR function call lets you map only a user-defined error code to a custom error message.
True. A RAISE_APPLICATION_ERROR function call does let you map a user-defined error code to a custom error message.
10. A call to the format_error_backtrace function from the utl_call_stack package creates a stack trace.
False. The format_error_backtrace function doesn’t belong to the utl_call_stack package. The format_error_backtrace function belongs to the dbms_utility package.


Multiple Choice:
11. Which of the following error codes belongs to a predefined exception? (Multiple answers
possible)
A. ORA-01402
B. ORA-01722
C. ORA-06548
D. ORA-01422
E. ORA-00001
B, C, and D are correct. The ORA-01722 error belongs to the predefined INVALID_NUMBER exception, the ORA-06548 error belongs to the NO_DATA_NEEDED exception, and the ORA-01422 error belongs to the TOO_MANY_ROWS exception.
12. Which of the following is a predefined exception keyword? (Multiple answers possible)
A. CURSOR_IS_OPEN
B. INVALID_NUMBER
C. LOGIN_DENIED
D. NO_DATA_FOUND
E. VALUE_INCORRECT
B, C, and D are correct. The predefined INVALID_NUMBER predefined error belongs to an ORA-01722 error, the predefined LOGIN_DENIED predefined error belongs to an ORA-01017 error, and the predefined NO_DATA_FOUND predefined error belongs to an ORA-01403 error. CURSOR_IS_OPEN and VALUE_INCORRECT are invalid predefined exceptions.

13. Which of the following lets you raise an exception in PL/SQL? (Multiple answers possible)
A. A THROW e; statement
B. A RAISE e; statement
C. A THROW; statement
D. A RAISE; statement
E. A RAISE_APPLICATION_ERROR function call
B and E are correct. The RAISE statement requires a locally declared exception variable. A RAISE_APPLICATION_ERROR function call is also correct.
14. Which of the following are functions of the utl_call_stack package? (Multiple answers possible)
A. The backtrace_error function
B. The backtrace_depth function
C. The error_number function
D. The subprogram_name function
E. The error_depth function
B, C, and E are correct. The backtrace_depth, error_number, and error_depth functions are valid elements of the utl_call_stack package.
15. Which of the following displays an HTML-ready stack trace? (Multiple answers possible)
A. The utl_call_stack.current_edition function
B. The dbms_utility.format_stack_trace function
C. The dbms_utility.format_error_backtrace function
D. All of the above
E. None of the above
C is correct. The format_error_backtrace function is the only valid way to generate a HTML-ready stack trace.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值