Challenge - 5 Problems
Error Handling Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Handling Null Pointer Exception in Kotlin Android
What will be the output when this Kotlin Android code runs and the nullable variable is null?
Android Kotlin
val userName: String? = null
val displayName = userName!!.length
println("Length: $displayName")Attempts:
2 left
💡 Hint
The double exclamation mark (!!) forces a non-null assertion.
✗ Incorrect
Using !! on a null value causes KotlinNullPointerException at runtime.
🧠 Conceptual
intermediate2:00remaining
Try-Catch Block Behavior in Kotlin Android
What is the output of this Kotlin code snippet in Android when an exception occurs inside the try block?
Android Kotlin
try { val result = 10 / 0 println("Result: $result") } catch (e: ArithmeticException) { println("Caught division by zero") } finally { println("Finally block executed") }
Attempts:
2 left
💡 Hint
Division by zero throws ArithmeticException.
✗ Incorrect
The exception is caught and handled, then finally block runs.
❓ lifecycle
advanced2:00remaining
Exception Handling in Android Activity Lifecycle
If an exception is thrown inside onCreate() of an Android Activity and not caught, what happens?
Attempts:
2 left
💡 Hint
Uncaught exceptions in lifecycle methods cause app crashes.
✗ Incorrect
Android does not catch uncaught exceptions in lifecycle methods; app crashes.
📝 Syntax
advanced2:00remaining
Correct Kotlin Syntax for Catching Multiple Exceptions
Which Kotlin code snippet correctly catches both IOException and NumberFormatException in Android?
Android Kotlin
fun parseData() {
try {
// code that may throw exceptions
} catch (e: IOException, e: NumberFormatException) {
println("Exception caught")
}
}Attempts:
2 left
💡 Hint
Kotlin does not support multiple exception types in one catch clause.
✗ Incorrect
Kotlin requires separate catch blocks for different exception types.
🔧 Debug
expert2:00remaining
Diagnosing Silent Failure in Coroutine Exception Handling
In this Kotlin coroutine code, why does the exception not crash the app or print the error message?
Android Kotlin
GlobalScope.launch {
try {
throw IllegalStateException("Error in coroutine")
} catch (e: Exception) {
// empty catch block
}
}
println("Coroutine launched")Attempts:
2 left
💡 Hint
Empty catch blocks swallow exceptions silently.
✗ Incorrect
The exception is caught but nothing is done, so no error is shown.