Exercises

Exception and Error Handling Across Python, Ruby, Java, and C

Explore how Python, Ruby, Java, and C detect, propagate, handle, and report errors. This quiz covers try blocks, catch and rescue clauses, cleanup guarantees, exception chaining, checked exceptions, resource management, errno, setjmp and longjmp, and language-specific best practices. Questions range from foundational syntax to subtle control-flow behavior and cross-language distinctions.

Answer the questions below and check the explanation for each answer.

0/19 answered

  1. 1

    In Python, when does the else block associated with try and except execute?

    Question 1
  2. 2

    What must Java code normally do when calling a method that may throw a checked exception?

  3. 3

    What is the primary purpose of an ensure clause in Ruby exception handling?

  4. 4

    What is the safest general pattern for using errno after calling a C library function?

  5. 5

    The diagram highlights KeyboardInterrupt in Python's exception hierarchy. Why is except Exception usually insufficient to catch it?

    Question 5
  6. 6

    If several resources are declared in one Java try-with-resources statement, in what order are they closed?

    Question 6
  7. 7

    In Python, what does raise NewError() from original_error establish?

  8. 8

    In Ruby, what does retry do when executed inside a rescue clause associated with a begin block?

    Question 8
  9. 9

    What does the C function perror typically print?

  10. 10

    Which Java multi-catch clause is invalid because its alternatives are related by inheritance?

    Question 10
  11. 11

    What does a bare raise statement do inside an active Python except block?

  12. 12

    Which exceptions does a Ruby rescue clause with no specified exception class catch by default?

  13. 13

    How does setjmp report initial execution versus a later return caused by longjmp in C?

    Question 13
  14. 14

    A Java method's try block throws an exception that matches its catch clause, and the method also has a finally block. Which execution order does the flow diagram represent?

    Question 14
  15. 15

    In Python, what does it mean if a context manager's __exit__ method returns a truthy value after receiving exception information?

    Question 15
  16. 16

    Which situation can prevent a Java finally block from executing?

  17. 17

    Inside a Ruby rescue clause, what does raise with no arguments normally do?

  18. 18

    What is the role of strerror in conventional C error reporting?

  19. 19

    Which statement best describes ordinary error handling in the C language?

Download the App now to have access to + 5000 free courses, exercises, certificates and lots of content without paying anything!

  • 100% free online courses from start to finish

    Thousands of online courses in video, ebooks and audiobooks.

  • More than 60 thousand free exercises

    To test your knowledge during online courses

  • Valid free Digital Certificate with QR Code

    Generated directly from your cell phone's photo gallery and sent to your email

Cursa app on the ebook screen, the video course screen and the course exercises screen, plus the course completion certificate