`
leonzhx
  • 浏览: 796646 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Item 63: Include failure-capture information in detail messages

阅读更多

1.  When a program fails due to an uncaught exception, the system automatically prints out the exception’s stack trace. The stack trace contains the exception’s string representation, the result of invoking its toString method. This typically consists of the exception’s class name followed by its detail message.

 

2.  It is critically important that the exception’s toString method return as much information as possible concerning the cause of the failure.

 

3.  To capture the failure, the detail message of an exception should contain the values of all parameters and fields that “contributed to the exception.”

 

4.  One way to ensure that exceptions contain adequate failure-capture information in their detail messages is to require this information in their constructors instead of a string detail message. The detail message can then be generated automatically to include the information:

public IndexOutOfBoundsException(int lowerBound, int upperBound, int index) {
    // Generate a detail message that captures the failure
    super("Lower bound: " + lowerBound + ", Upper bound: " + upperBound + ", Index: " + index);
    // Save failure information for programmatic access
    this.lowerBound = lowerBound;
    this.upperBound = upperBound;
    this.index = index;
}

 

It may be appropriate for an exception to provide accessor methods for its failure-capture information.

 

分享到:
评论

相关推荐

    Effective Java 3rd edition(Effective Java第三版英文原版)附第二版

    Item 75: Include failure-capture information in detail messages Item 76: Strive for failure atomicity Item 77: Don’t ignore exceptions 11 Concurrency Item 78: Synchronize access to shared mutable ...

    fatal error C1083: Cannot open include file:config-win.h修复工具.rar

    网友分享的能够解决fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory问题的程序。MySQL-python-1.2.3.win32-py2.7.exe-32位MySQL-python-1.2.3.win-amd64-py...

    p7331323_10204_AIX5L

    Information in this document applies to any platform. Description The following errors may be reported: ORA-00603: ORACLE server session terminated by fatal error ORA-27504: IPC error creating OSD ...

    Android Recipes: A Problem-Solution Approach, 3rd Edition

    It’s updated to include the KitKat Android 4.4 SDK as well as earlier releases. Instead of abstract descriptions of complex concepts, in Android Recipes, you’ll find live code examples. When you ...

    EurekaLog_7.5.0.0_Enterprise

    2)....Fixed: Range check error in processes information for x64 machines (affects startup of any EurekaLog-enabled module) 3)....Fixed: Auto-detect personality by project extension if --el_mode switch...

    Qt5.9.9+opencv3.4.1源码及工具包demo

    INCLUDEPATH += C:/OpenCV-MinGW-Build-OpenCV-3.4.1/include \ C:/OpenCV-MinGW-Build-OpenCV-3.4.1/include/opencv \ C:/OpenCV-MinGW-Build-OpenCV-3.4.1/include/opencv2 LIBS += C:/OpenCV-MinGW-Build-...

    广东专中考英语话题二环境PPT课件.pptx

    - "include"可以用来表示包含某个部分,如"Her hobbies include reading and painting."(她的爱好包括阅读和绘画。) - "including"作为介词,常用于列举时,如"Many people took part in the fight against the ...

    Python安装MySQL安装包 64位 py2.7 [exe文件]

    Python安装MySQL文件,EXE文件 ..._mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory 原来还是驱动问题,不管mysql的事。 希望该安装包对你有所帮助~

    Real-Time C++: Efficient Object-Oriented and Template Microcontroller

    The appendices include a brief C++ language tutorial, information on the real-time C++ development environment and instructions for building GNU GCC cross-compilers and a microcontroller circuit. ...

    Debugging Malloc Lab: Detecting Memory-Related Errors

    Information that you might want to store in this extra (header, footer) area include: a "fence" immediately around the requested payload with a known value like 0xCCDEADCC, so that you can check if ...

    springmodules-cache.xsd&springmodules-ehcache.xsd.rar

    java.sun.com/xml/ns/javaee":include-prelude, "http://java.sun.com/xml/ns/javaee":include-coda, "http://java.sun.com/ xml/ns/javaee":deferred-syntax-allowed-as-literal, ...

    Name : ncurses-devel Version : 5.7

    Name : ncurses-devel Version : 5.7 Vendor : Fedora Project Release : 2.20090207.fc11 Date ...RPM found in directory: /mirror/archive.fedoraproject.org/fedora/linux/releases/11/Fedora/i386/os/Packages

    dev-c++ unable to run program file 问题解决办法

    * “C++ 包含文件”路径:C:\Dev-Cpp\include\c++\mingw32 * “C++ 包含文件”路径:C:\Dev-Cpp\include\c++\backward * “C++ 包含文件”路径:C:\Dev-Cpp\include 步骤 3:设置环境选项 最后,需要设置环境选项...

    C++ boost::asio编程-域名解析详细介绍

    #include stdafx.h #include boost/asio.hpp #include boost/shared_ptr.hpp #include boost/thread.hpp #include <boost>//使用字符串转换功能 using namespace std; using namespace boost::asi

    MFC对EXCEL的操作:修改单元格格式,背景,字体颜色

    cell->Borders->_Item[XlBordersIndex::xlDiagonalDown]->LineStyle = XlLineStyle::xlContinuous; cell->Borders->_Item[XlBordersIndex::xlDiagonalUp]->LineStyle = XlLineStyle::xlContinuous; cell->Borders->_...

    gatsby-plugin-react-svg:将svg-react-loader添加到gatsby Webpack配置中

    // In your gatsby-config.js plugins: [ { resolve : "gatsby-plugin-react-svg" , options : { rule : { include : / assets / // See below to configure properly } } } ] ; 配置 rule插件选项可用于...

    JNI技术手册 c/c++调用java

    #include "HelloWorld.h" JNIEXPORT void JNICALL Java_HelloWorld_sayHello(JNIEnv *env, jobject obj) { printf("Hello from C/C++ via JNI\n"); } ``` - **测试:** - 将C/C++代码编译为DLL。 - 在Java...

    sakis3g:sakis3g - 支持 3g4g 树莓派调制解调器

    变化#include 依赖关系/ USB-modeswitch / usb_modeswitch.h到#include <libusb> 或者2b. sudo cp /usr/include/libusb-1.0/libusb.h /usr/include 或者2c。 sudo ln -s /usr/include/libusb-1.0/libusb.h /usr/...

    jekyll-include-cache:一个Jekyll插件,用于缓存Liquid包含的呈现

    gem 'jekyll-include-cache' 将以下内容添加到您站点的配置文件中: plugins : - jekyll-include-cache :light_bulb: 如果您使用的Jekyll版本低于3.5.0,请使用gems键而不是plugins 。 将模板中的{% include ...

    mingw32 2.95

    2. include目录:包含必要的头文件,供开发者在编写代码时引用Windows API和其他系统库。 3. lib目录:存储编译和链接所需的静态库和动态库。 4. share目录:可能包含一些共享数据,如man手册页等。 使用 MingW32 ...

Global site tag (gtag.js) - Google Analytics