#9 error-handling + exceptions + generics Flashcards

(9 cards)

1
Q

how to exit the program if an error occurred

A

if(condition indicating error){
system.err.println (“Goodbye Cruel JVM”);
system.exit(-1);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

error handling with exceptions
(you don’t have to throw an exception, you could just do if (exception occurred){
return whatever code you please;}

A
void method1(){
if(exception occurred)
throw new ExceptionType();
}
void method2(){
try{
method1();
} catch (ExceptionType e) {
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

exceptions are objects derived from which class?

A

throwable
Throwable (); //no error message
Throwable(String msg); // with error message
String getMessage (); //return error message
void printStackTrace(); //record methods called, and location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

two types of errors

A

checked errors: must be handled by the programmer

unchecked errors: serious errors that a typical program should not be required to handle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

IO Exception(java.io)

A

used for generic I/O errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

IllegalArgumentException(java.lang)

A

if method has passed in an illegal or inappropriate argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

NullPointerException(java.lang)

A

a null reference is dereferenced

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

ArrayIndexOutOfBoundsException(java.lang)

A

array subscript is invalid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

UnsupportedOperationException

A

a called operation does not exist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly