zoukankan      html  css  js  c++  java
  • 自定义异常时如何定义checked异常和unchecked异常

    When defining your own exception type, study the existing exception classes in the Java API and try to extend a related exception class. For example, if you’re creating a new class to represent when a method attempts a division by zero, you might extend classArithmeticException because division by zero occurs during arithmetic. If the existing classes are not appropriate superclasses for your new exception class, decide whether your new class should be a checked or an unchecked exception class. If clients should berequired to handle the exception, the new exception class should be a checked exception (i.e., extend Exception but notRuntimeException). The client application should be able to reasonably recover from such an exception. If the client code should be able to ignore the exception (i.e., the exception is an unchecked one), the new exception class should extend RuntimeException.

  • 相关阅读:
    C#
    C#
    C#
    创建一个ROS包
    创建一个工作空间
    ROS的文件系统
    单一职责原因
    策略模式
    UML类图
    简单工厂模式
  • 原文地址:https://www.cnblogs.com/IcanFixIt/p/4733324.html
Copyright © 2011-2022 走看看