i. Grades online
i. Coming soon – stay tuned
i. String methods
ii. Scanner
iii. <String>.split(<String
delimiter>);
i. Signal that something went wrong
ii. Some examples:
1. ArrayOutOfBoundsException
2. NullPointerException
3. ArithmeticException
4. FileNotFoundException
i. Recognizing that an exception has
occurred. For instance, unable to open
the filename specified.
i. Doing something productive with that
exception
ii. What exactly this means will depend on the
context of the exception
1. Different exceptions/situations require
different handling.
if(/*Something bad happens*/) {
throw new <Type of Exception>();
}
if(/*Something bad happens*/) {
throw new <Type of
Exception>(“Abort! Something bad happened!”);
}
i. try – we’ll try to execute some code. It might throw an exception before it is
completed.
ii. catch – we’ll catch a specific type of
exception that might occur in the code, and handle it accordingly.
try {
//Code
that might cause exception
}
catch(<Type of exception> <object name>)
{
//Do
something, such as:
//<objectName>.printStackTrace();
}
i. These are issues related to our computer or
something else, such as running out of memory.
We won’t worry about these.
i. These are exceptions that are
‘preventable’. They are the result of
buggy code.
ii. For instance: ArrayIndexOutOfBoundsException,
NullPointerException
iii. Java does not require us to handle these
i. These are exceptions that we can’t predict
ii. For instance: FileNotFoundException,
IOException
iii. Java requires us to handle these
iv. All checked exceptions must be handled
somehow
1. If we say that the method throws that
exception, it will be passed up the call stack to the method that called this
method.
2. If we handle the exception with a try/catch
block, we do not keep searching up the call stack – the JVM is satisfied.
3. If there is an exception that can be thrown
by the code in the try block, but it is not handled in a catch block, we still
must acknowledge that the method throws that exception – we will then search up
the call stack hierarchy.
i. UncheckedException.java,
CheckedException.java
1. ArithmeticException and InputMismatchException
2. FileNotFoundException
3. OutOfMemoryError
a. Can’t catch…
4. What are the differences between the three?
i. Must throw it in callee
ii. Then, catch it in caller