Bird
0
0

Why does the safe call operator ?. not prevent exceptions like IndexOutOfBoundsException in Kotlin?

hard📝 Conceptual Q10 of 15
Kotlin - Null Safety
Why does the safe call operator ?. not prevent exceptions like IndexOutOfBoundsException in Kotlin?
ABecause it converts exceptions to null silently
BBecause it disables all exceptions including index errors
CBecause it only checks for null, not invalid indices or other errors
DBecause it only works with primitive types
Step-by-Step Solution
Solution:
  1. Step 1: Understand safe call operator purpose

    The safe call operator only checks if the object is null before calling a method or property.
  2. Step 2: Recognize limitations of safe call

    It does not handle exceptions caused by invalid operations like accessing invalid list indices.
  3. Final Answer:

    Because it only checks for null, not invalid indices or other errors -> Option C
  4. Quick Check:

    Safe call protects null, not other runtime exceptions [OK]
Quick Trick: Safe call checks null only, not other exceptions [OK]
Common Mistakes:
MISTAKES
  • Thinking safe call disables all exceptions
  • Believing it converts exceptions to null
  • Assuming it works only on primitives

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes