标签:
注意:
1.Java中的所有异常都是由Throwable类的子类生成的对象,所有的异常类都是Throwable类的子类或子类的子类。Throwable类是Object类的直接子类,Error类和Exception类是Throwable类的两个直接子类。
Error 错误类
java.lang.Error
错误类一般是指虚拟机相关的
Exception 异常类
2.java.lang.Exception类是Java中所有异常的直接或间接父类
java中异常处理是通过5个关键字实现的try,catch,finally,throw,throws
throw与throws的区别:
throw是语句抛出异常,throws是可能发生异常抛出的声明
异常捕获语法:
try { //将可能出错的代码放在此处 } catch (Exception e) { //若try块中发生异常那么将被catch捕获到 }finally{ //无论是否出现异常finally都会执行 //若try或catch中出现System.exit(0)finally块将不执行,因为java虚拟机已被关闭 }
多路异常捕获语法:
//多路异常捕获 try { //将可能出错的代码放在此处 } catch (NullPointerException e) { //多路异常捕获子类异常在前 }catch (Exception e) { //父类异常在后 }finally{ //无论是否出现异常finally都会执行 //若try或catch中出现System.exit(0)finally块将不执行,因为java虚拟机已被关闭 }
多路异常捕获要注意:子类异常在前,父类异常在后
配置log4j图片教程(无使用教程):
==========================================================================
以下是Exception直接已知子类 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, JMException, LastOwnerException, LineUnavailableException, MidiUnavailableException
MimeTypeParseException, NamingException, NoninvertibleTransformException, NoSuchFieldException, NoSuchMethodException
NotBoundException, NotOwnerException, ParseException, ParserConfigurationException, PrinterException, PrintException
PrivilegedActionException, PropertyVetoException, RefreshFailedException, RemarshalException, RuntimeException, SAXException
ServerNotActiveException, SQLException, TimeoutException, TooManyListenersException, TransformerException, UnmodifiableClassException
UnsupportedAudioFileException, UnsupportedCallbackException, UnsupportedFlavorException, UnsupportedLookAndFeelException
URISyntaxException, UserException, XAException, XMLParseException, XPathException
==================================================================================================
标签:
原文地址:http://www.cnblogs.com/liuguangyiduan/p/4905906.html