zoukankan      html  css  js  c++  java
  • 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,
  • 相关阅读:
    MySQL日志系统
    MySQL基础架构
    Java操作XML牛逼利器JDOM&DOM4J
    SAX方式解析XML
    DOM方式解析XML
    Jquery Ajax
    Jquery动画效果
    angular6新建项目
    mysql命令行使用
    git常用命令
  • 原文地址:https://www.cnblogs.com/langtianya/p/3039324.html
Copyright © 2011-2022 走看看