Correct code

Report a typo

Which of these try-catch statements below are correct?

Code is considered correct not just when it's technically correct, but also when it runs smoothly and always compiles as expected.

a)

try {
    // code that may throw an exception
} catch (e: RuntimeException) {
    // ...
} catch (e: Exception) {
    // ...
}

b)

try {
    // code that may throw an exception
} catch (e: Exception) {
    // ...
} catch (e: RuntimeException) {
    // ...
}

c)

try {
    // code that may throw an exception
} catch (Exception) {
    // ...
} catch (RuntimeException) {
    // ...
}

d)

try {
    // code that may throw an exception
} catch 1: (e: ArithmeticException) {
    // ...
} catch 2: (e: RuntimeException) {
    // ...
} catch 3: (e: Exception) {
    // ...
}
Select one or more options from the list
___

Create a free account to access the full topic