• JAVA 的checked异常和unchecked异常


    • 什么是unchecked异常?

    即RuntimeException(运行时异常) 不需要try...catch...或throws 机制去处理的异常

    • 列举最常用的五种RuntimeException:

    这是JAVA认证考试中最常见的题目,事实上,runtime exception中最常见的,经常碰到的,也就5,6种,如下:

    ArithmeticException int a=0; int b= 3/a;
    ClassCastException: Object x = new Integer(0); System.out.println((String)x);
    IndexOutOfBoundsException ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException int [] numbers = { 1, 2, 3 }; int sum = numbers[3];
    IllegalArgumentException NumberFormatException int a = Interger.parseInt("test");
    NullPointerExceptionextends  
    • 除了RuntimeException,其他继承自java.lang.Exception得异常统称为Checked Exception,他们有多少种呢?

    下面是JDK API中列出的异常类: 除了RuntimeException以外的,都是checked Exception

    java.lang.Object java.lang.Throwable java.lang.Exception 所有已实现的接口: Serializable 直接已知子类: AclNotFoundException, ActivationException, AlreadyBoundException, ApplicationException, AWTException, BackingStoreException, BadAttributeValueExpException, BadBinaryOpValueExpException, BadLocationException, BadStringOperationException, BrokenBarrierException, CertificateException, ClassNotFoundException, CloneNotSupportedException, DataFormatException, DatatypeConfigurationException, DestroyFailedException, ExecutionException, ExpandVetoException, FontFormatException, GeneralSecurityException, GSSException, IllegalAccessException, IllegalClassFormatException, InstantiationException, InterruptedException, IntrospectionException, InvalidApplicationException, InvalidMidiDataException, InvalidPreferencesFormatException, InvalidTargetObjectTypeException, InvocationTargetException, IOException, JAXBException, JMException, KeySelectorException, LastOwnerException, LineUnavailableException, MarshalException, MidiUnavailableException, MimeTypeParseException, MimeTypeParseException, NamingException, NoninvertibleTransformException, NoSuchFieldException, NoSuchMethodException, NotBoundException, NotOwnerException, ParseException, ParserConfigurationException, PrinterException, PrintException, PrivilegedActionException, PropertyVetoException, RefreshFailedException, RemarshalException, RuntimeException, SAXException, ScriptException, ServerNotActiveException, SOAPException, SQLException, TimeoutException, TooManyListenersException, TransformerException, TransformException, UnmodifiableClassException, UnsupportedAudioFileException, UnsupportedCallbackException, UnsupportedFlavorException, UnsupportedLookAndFeelException, URIReferenceException, URISyntaxException, UserException, XAException, XMLParseException, XMLSignatureException, XMLStreamException, XPathException

    我经常碰到的checked exception:

    AWTException,

    CertificateException,

    ClassNotFoundException,

    CloneNotSupportedException,

    InterruptedException,

    InstantiationException,

    IllegalClassFormatExceptionm,

    IllegalAccessException,

    IOException,

    InvocationTargetException,

    NoSuchFieldException,

    NoSuchMethodException,

    ParserConfigurationException,

    SOAPException,

    SQLException,

    TimeoutException,
  • 相关阅读:
    基于Qt的图像处理技术和算法
    项目中使用到的算法
    C++将数组的元素顺序随机打乱
    Windows环境下 RabbitMQ集群配置
    Nginx负载均衡配置
    SQL Server Profiler:使用方法和指标说明
    如何查看IIS并发连接数
    23种设计模式的趣味理解
    C# 开源框架(整理)
    git 简易教程
  • 原文地址:https://www.cnblogs.com/langtianya/p/3039324.html
Copyright © 2020-2023  润新知