Challenge: Using finally for Cleanup
Task
Swipe to start coding
Practice using a try-catch-finally structure to simulate resource management and cleanup:
- In the
CleanUpProcessmethod, print"Resource acquired"at the start of the method. - Inside a
tryblock, print"Processing resource"and then throw aSystem.Exceptionwith the message"Unexpected error". - In the
catchblock, print"Exception handled". - In the
finallyblock, print"Resource released". - Do not use any file or stream operations; focus only on the flow and printed messages.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 6
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 4.17
Challenge: Using finally for Cleanup
Swipe to show menu
Task
Swipe to start coding
Practice using a try-catch-finally structure to simulate resource management and cleanup:
- In the
CleanUpProcessmethod, print"Resource acquired"at the start of the method. - Inside a
tryblock, print"Processing resource"and then throw aSystem.Exceptionwith the message"Unexpected error". - In the
catchblock, print"Exception handled". - In the
finallyblock, print"Resource released". - Do not use any file or stream operations; focus only on the flow and printed messages.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 6
single