Mind map
Chapter 6
Map content
Chapter 6
Exceptions
- Event that alter program flow
- Throwable supperclass
- for all objects
- java.lang.Throwable
- java.lang.Exception(Checked Exceptions)
- java.lang.RuntimeException (Unchecked Exceptions)
- java.lang.Error
- java.lang.Exception(Checked Exceptions)
- Error
- something went wrong and your program should not attempt to recover from it.
- Not okay for program to catch
- No required to handle or declare
- something went wrong and your program should not attempt to recover from it.
- Exception(Checked)
- Java requires code to
- handle them
- declare them in method
- Okay to catch
- Java requires code to
- RuntimeException(Unchecked)
- unexpected but not necessarily fatal
- Okay to catch
- No required to handle or declare
- unexpected but not necessarily fatal
- keywords
- throw
- Tells Java to throw an exception
- throws
- might throw an exception
- throw
Try Statement
- Java use it to separate the logic
- might throw an exception
- from the logic to handle that exception.
- might throw an exception
- Syntax
- Try Block
- If doesn't throw an exception
- catch block doesn't run
- Needs:
- to have a catch or finally block
- If doesn't throw an exception
- Catch Block
- Exception handler
- catch exception type must match the try exception error
- must have a parenthesis
- (exception_type identifier)
- Finally Block
- finally must be after a catch block
- not viceversa
- Run code at the end of the statement
- Always executes whether or not an exception occurs
- except if System.exit(0)
- Always executes whether or not an exception occurs
- finally must be after a catch block
- Try Block
- When a superclass is caught before a subclass
- compiler error unreachable code
- Java use it to separate the logic
Common Exception Types
- Runtime Exceptions
- thrown by JVM
- ArithmeticException
- when code attempt to divide by zero
- ArrayIndexOutOfBoundsException
- when code uses an illegal index to access an array
- ClassCastException
- when cast an exception to a subclass of which it is not an instance
- ArithmeticException
- thrown by programmer
- IllegalArgumentException
- indicate that a method has been passed an illegal argument
- NullPointerException
- when there is a null reference when an object is required
- NumberFormatException
- when try to convert a string to a numeric type and the string doesn't have an appropiate format
- IllegalArgumentException
- thrown by JVM
- Checked Exceptions
- thrown programmatically
- IOException
- when there's a problem reading or writing a file.
- FileNotFoundException
- when trying to reference an unexisting file
- subclass of IOException
- IOException
- thrown programmatically
- Errors
- thrown by JVM
- ExceptionInInitializerError
- when static initializer throws an Exception and doesn't handle it
- StackOverflowError
- when a method calls itself to many times
- NoClassDefFoundError
- when a class code is available at compile time but not at runtime
- ExceptionInInitializerError
- thrown by JVM
- Runtime Exceptions
Information
- Description
- Mind Map on Chapter 6, created by Enrique López Mata on 10/01/2019.
- Created by
- Enrique López Mata
- Views
- 0
- Rating