Programming - 4 - Exceptions Flashcards

1
Q

What is an Exception?

A

Indication of a problem that occurs during rpgram execution

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

Example of Checked Exceptions

A

IOException

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

Examples of Unchecked Exceptions

A
  • ArrayIndexOutOfBoundsException when trying to access an array element with a too large index
  • ArithmeticException for integer division by zero
  • InputMismatchException when an inappropriate input to what expected is passed, e.g. an integer is expected from the standard input and a double or a string is passed
  • NumberFormatException e.g. when trying to convert a string to an integer but the string does not have the appropriate format, “12” is ok but “1b” isn’t
  • NullPointerException when trying to access an object through a null object reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Basic Exception Code

A

try {

//code you test on

}

catch(NumberFormatExcepion e) { //you can print the exception }

catch(ArithmeticException e) {…}

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