Mid Term Study Error types + Control Handling Flashcards
Explain these exceptions:
IOException
ArrayIndexOutOfBoundsException
ArithmeticException
IllegalArgumentException
InputMismatchException
IOException - Input/Output failure like failure to read from a file
ArrayIndexOutOfBoundsException - index not in array
ArithmeticException - Trying to divide by 0 or square root by a negative
IllegalArgumentException - Inappropriate argument passed
InputMismatchException - Incorrect datatype given
Name all java primitive datatypes and their bit size
byte size 8 bits - For byte size ints
short 16 bits - For short size ints
int 32 bits - for int
long 64 bits - For long size ints
float 32 bits - includes decimals
double 64 bits - includes decimals
char 16 bits - represents a single 16-bit unicode character
try/catch syntax?
try {
//If an exception is thrown go to the catch
}
catch(ArithmeticException err){
//In this case arithmetic exceptions will be resolved in this catch block
System.out.println(“Error: “ + err);
}
NOTE: Can also use catch(Exception err){} to catch all error types