Some exceptions are actually what are called unchecked exceptions. In our discussion of the exception hierarchy, we mentioned that these are (a) RuntimeExceptions: things like NullPointerException that could pretty much occur 'at any time' due to a programming error; and (b) Errors: serious errors that we basically don't expect to deal with except "in emergency", such as OutOfMemoryError.

How unchecked exceptions differ from regular exceptions

Unchecked exceptions behave as follows:

  • They they don't have to be explicitly caught. When an unchecked exception occurs, such as a NullPointerException, ClassCastException, OutOfMemoryError etc, Java will "handle" the exception automatically (see below).
  • Methods and constructors don't have to explicitly state that they can throw an unchecked exception. It's taken for granted that any method can throw them.
  • Indeed, certain Java bytecode instructions (such as array access, invoking a method on an object, integer division etc) can actually throw an unchecked exception.

What happens when an unchecked exception occurs

An uncaught exception is an (unchecked) exception that isn't caught in a try/catch block. We'll take both a simplistic view of how uncaught exceptions are handled and then a more detailed and correct view, because the detailed version can be quite complex (and knowing it all is unnecessary) if you're a beginner to Java.





저작자 표시 비영리 변경 금지

'개발/활용정보 > Java' 카테고리의 다른 글

osgi 공부 ^^;;;  (0) 2013.07.10
osgi shell command  (0) 2013.02.21
uncaughtException  (0) 2012.07.19
Code generation using Javadoc  (0) 2012.07.11
Java 리플렉션에 대한 재고(reflection)  (0) 2012.07.10
이클립스에서 Java Heap Size 설정하기  (0) 2012.02.15
Trackback 0 And Comment 0

티스토리 툴바