Exception Handling Flashcards
what is an exception?
an error which occurs during a normal flow of a program
why is exceptions bad?
they cause disrupted and abnormally terminates program
exception handling helps to … (4 points)
1- try to recover
2- retry operation
3- display meaningful error
4- terminating the whole program but in a better way
we use what operations for exception handling
try-catch or try-catch-finally
if i divide by zero what type of exception occurs
ArithmeticException
if an array index is more than the size or equals to -1 which exception is used
ArrayIndexOutOfBoundsException
types of exceptions
checked and unchecked
checked exceptions are handled at (compile, runtime)?
compile time
how to fix checked exceptions
try-catch, and extend a throwable class either directly or indirectly
examples of checked exceptions
FileNotFoundException and PrinterException
unchecked exceptions occurs where?
outside the program
most of the time unchecked exception can be expected or recovered (t or f)
false, most of the time it cannot be expected or recovered from
how to fix unchecked exceptions?
must extend RuntimeException class directly or indirectly
examples for unchecked exceptions?
NullPointerException , ClassCastException
printwriter pckage is
java.io
if theres an exception that a file can’t be written into this exception is called?
IOException
can we make multiple catches?
yes
exceptions should be ordered from…
very special to very general
exception class must be placed at…
the very end
finally block executed …
regardless the exception is thrown or not
printwriter must be closed, if not closed it…
reserves unwanted memory
throwing an exception comes in two forms …
Java Exception, User Defined Exception
to make a user defined exception class …
make a class exception that extends class (main java class) exception
public class numberexception extends exception
To use a user defined class…
we use the keyword throws in the declaration and then throw an object of the exception class
public int add () throws numberexception{
throw new numberexception (values);
}