Exception Handling Flashcards

1
Q

what is an exception?

A

an error which occurs during a normal flow of a program

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

why is exceptions bad?

A

they cause disrupted and abnormally terminates program

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

exception handling helps to … (4 points)

A

1- try to recover
2- retry operation
3- display meaningful error
4- terminating the whole program but in a better way

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

we use what operations for exception handling

A

try-catch or try-catch-finally

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

if i divide by zero what type of exception occurs

A

ArithmeticException

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

if an array index is more than the size or equals to -1 which exception is used

A

ArrayIndexOutOfBoundsException

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

types of exceptions

A

checked and unchecked

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

checked exceptions are handled at (compile, runtime)?

A

compile time

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

how to fix checked exceptions

A

try-catch, and extend a throwable class either directly or indirectly

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

examples of checked exceptions

A

FileNotFoundException and PrinterException

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

unchecked exceptions occurs where?

A

outside the program

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

most of the time unchecked exception can be expected or recovered (t or f)

A

false, most of the time it cannot be expected or recovered from

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

how to fix unchecked exceptions?

A

must extend RuntimeException class directly or indirectly

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

examples for unchecked exceptions?

A

NullPointerException , ClassCastException

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

printwriter pckage is

A

java.io

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

if theres an exception that a file can’t be written into this exception is called?

A

IOException

17
Q

can we make multiple catches?

A

yes

18
Q

exceptions should be ordered from…

A

very special to very general

19
Q

exception class must be placed at…

A

the very end

20
Q

finally block executed …

A

regardless the exception is thrown or not

21
Q

printwriter must be closed, if not closed it…

A

reserves unwanted memory

22
Q

throwing an exception comes in two forms …

A

Java Exception, User Defined Exception

23
Q

to make a user defined exception class …

A

make a class exception that extends class (main java class) exception

public class numberexception extends exception

24
Q

To use a user defined class…

A

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);
}