最常见的检查和未检查的Java异常? [英] Most common checked and unchecked Java Exceptions?

查看:129
本文介绍了最常见的检查和未检查的Java异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,没有办法找出一个方法抛出的异常,而不是逐一查找API文档。



由于这是没有选择的,我想扭转研究,并询问您在处理时遇到的最常见的异常和运行时异常: / p>


  • Casting

  • 数组

  • Vector,ArrayList,HashMap等等

  • IO(文件类,流,过滤器,...)

  • 对象序列化

  • 线程(wait(),sleep()等)

  • 或任何被认为是基本Java的东西



我意识到这可能是主观和无聊,但它是一个类测试,我真的不知道更好。

解决方案

假设以下是java.lang,除非另有指定:




  • Casting :ClassCastException

  • 数组:ArrayIndexOutOfBoundsException,NullPointerException

  • 集合:NullPointerException,ClassCastException你不是使用自动装箱,而是拧紧它)

  • IO :java.io.IOException,java.io.FileNotFoundException,java.io.EOFException

  • 序列化:java.io.ObjectStreamException(AND ITS SUBCLASSES,我也是懒惰的枚举)

  • 线程:InterruptedException,SecurityException,IllegalThreadStateException

  • 所有情况下都可能有共同之处:NullPointerException,IllegalArgumentException



    • 您可以很好地查看Java网站的软件包摘要页面。这是一个: http://java.sun.com/j2se/1.4.2/docs/api/java/io /package-summary.html


      As far as I understand, there is no way to find out which exceptions a method throws without looking up the API docs one-by-one.

      Since that is no option, I'd like to reverse the research and ask you which are the most common Exceptions and RuntimeExceptions you've come across when dealing with:

      • Casting
      • Arrays
      • Vector, ArrayList, HashMap, etc.
      • IO (File class, streams, filters, ...)
      • Object Serialization
      • Threads (wait(), sleep(), etc.)
      • or anything else that is considered "basic Java"

      I realize that this might be subjective and boring but it is for a class test and I really don't know better.

      解决方案

      Assume the below are java.lang unless I specify otherwise:

      • Casting: ClassCastException
      • Arrays: ArrayIndexOutOfBoundsException, NullPointerException
      • Collections: NullPointerException, ClassCastException (if you're not using autoboxing and you screw it up)
      • IO: java.io.IOException, java.io.FileNotFoundException, java.io.EOFException
      • Serialization: java.io.ObjectStreamException (AND ITS SUBCLASSES, which I'm too lazy to enumerate)
      • Threads: InterruptedException, SecurityException, IllegalThreadStateException
      • Potentially common to all situations: NullPointerException, IllegalArgumentException

      You would do well to look at Java site's Package Summary pages. Here's one: http://java.sun.com/j2se/1.4.2/docs/api/java/io/package-summary.html

      这篇关于最常见的检查和未检查的Java异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆