Exercises
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
Auto audio on: the next questions will be read aloud when you click Continue.
The else block runs when control reaches the end of the try block without an exception. It keeps successful-path code separate from the protected operations.
Java's compiler normally requires a checked exception to be caught or declared in the calling method's throws clause.
Ruby's ensure clause is used for cleanup that should run during normal completion and exception propagation, such as closing a file.
errno may contain a stale value after a successful call. First test the function's documented failure result, then inspect errno when its contract says to do so.
KeyboardInterrupt is a direct descendant of BaseException rather than Exception. This prevents broad application-level handlers from unintentionally swallowing user interrupts.
Try-with-resources closes resources in reverse declaration order, similar to unwinding a stack. This is useful when later resources depend on earlier ones.
The from syntax creates explicit exception chaining. Python stores the original exception as the new exception's cause and displays that relationship in the traceback.
Ruby's retry restarts the associated begin block. It should be combined with a retry limit or changed conditions to avoid an infinite loop.
perror writes an optional prefix and a system-provided description corresponding to the current errno value, normally to standard error.
A multi-catch cannot combine a type with one of its subclasses. Because IOException extends Exception, the two alternatives overlap and cause a compile-time error.
A bare raise reraises the active exception while preserving its traceback, making it useful after partial handling or logging.
An unqualified Ruby rescue catches StandardError and its descendants. Serious exceptions outside that branch are not caught by default.
setjmp returns 0 when saving the environment. After longjmp restores that environment, it appears to return a nonzero value; a zero argument to longjmp is converted to 1.
When the exception matches, Java transfers control from try to catch. The finally block then runs before control continues beyond the statement.
A truthy return from __exit__ tells Python that the exception has been handled. A false value allows the exception to propagate.
A finally block normally runs despite return statements or handled exceptions. It may not run if the JVM terminates abruptly, such as after System.exit or a fatal process failure.
Within a rescue clause, a bare raise reraises the current exception. This is useful when the handler cannot fully recover after logging or cleanup.
strerror maps an error number, commonly errno, to an implementation-provided descriptive string. It does not itself determine whether a function failed.
C has no native try-and-catch exception mechanism. APIs usually communicate failure through documented return values, status codes, errno, output parameters, or application-specific conventions.

Free CourseLearn Python
13h00m
17 exercises

Free CourseJava Programming
9h15m
48 exercises

Free CourseCreate Desktop App
5h33m
30 exercises

Free CourseRuby on Rails
9h39m
34 exercises

Free CourseJava
22h17m
28 exercises

Free CourseC# Sharp for beginner
3h55m
15 exercises

Free CourseC++ as your first Programming Language
5h12m
23 exercises

Free CourseJava for beginners
26h50m
49 exercises
Thousands of online courses in video, ebooks and audiobooks.
To test your knowledge during online courses
Generated directly from your cell phone's photo gallery and sent to your email
Download our app via QR Code or the links below:.
+ 10 million
students
Free and Valid
Certificate
60 thousand free
exercises
4.8/5 rating in
app stores
Free courses in
video and ebooks