Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of a try-catch block in C#?
A try-catch block is used to handle errors (exceptions) that might happen during program execution, so the program can continue running safely instead of crashing.
Click to reveal answer
beginner
What happens if an exception occurs inside the try block?
The program immediately stops running the try block and jumps to the catch block that matches the exception type to handle the error.
Click to reveal answer
beginner
Can code after the try-catch block run if an exception is caught?
Yes, after the catch block finishes, the program continues running the code that comes after the try-catch block.
Click to reveal answer
intermediate
What is the role of the finally block in try-catch-finally?
The finally block runs code that must execute no matter what, whether an exception happened or not, like closing files or releasing resources.
Click to reveal answer
beginner
If no exception occurs in the try block, does the catch block run?
No, if the try block runs without errors, the catch block is skipped and the program continues normally.
Click to reveal answer
What happens when an exception is thrown inside a try block?
AExecution jumps to the matching catch block.
BThe program immediately stops running.
CThe code after the try block runs first.
DThe exception is ignored.
✗ Incorrect
When an exception occurs, the program jumps to the catch block that matches the exception type to handle it.
Which block always runs regardless of exceptions?
Afinally
Bcatch
Ctry
Dnone
✗ Incorrect
The finally block always runs after try and catch, whether or not an exception occurred.
If no exception occurs, which blocks run?
Atry and catch
Btry and finally
Ccatch and finally
Dtry only
✗ Incorrect
If no exception happens, the try block runs, then the finally block runs if present.
Can multiple catch blocks be used for one try block?
AOnly if they are nested.
BNo, only one catch block is allowed.
COnly if the exceptions are the same type.
DYes, to handle different exception types.
✗ Incorrect
Multiple catch blocks can be used to handle different types of exceptions separately.
What happens to code after the try-catch-finally block?
AIt runs only if no exception occurred.
BIt runs only if an exception was caught.
CIt always runs after the try-catch-finally block finishes.
DIt never runs if an exception occurs.
✗ Incorrect
After the try-catch-finally block finishes, the program continues running the code that follows.
Explain the flow of execution in a try-catch-finally block when an exception occurs.
Think about what happens step-by-step when an error happens inside try.
You got /6 concepts.
Describe what happens if no exception occurs inside the try block.
Consider the normal flow without errors.
You got /4 concepts.
Practice
(1/5)
1. What happens when an exception occurs inside a try block in C#?
easy
A. The program immediately jumps to the catch block to handle the error.
B. The program ignores the error and continues running the try block.
C. The program stops running without executing any further code.
D. The program restarts the try block from the beginning.
Solution
Step 1: Understand try-catch flow
The try block runs code that might cause an error.
Step 2: Exception triggers catch block
If an error happens, control moves to the catch block to handle it.
Final Answer:
The program immediately jumps to the catch block to handle the error. -> Option A
Quick Check:
Exception in try -> catch runs [OK]
Hint: Errors in try always jump to catch block [OK]
Common Mistakes:
Thinking the program ignores errors in try
Assuming the program restarts try block
Believing the program stops without catch
2. Which of the following is the correct syntax to catch an exception in C#?
easy
A. try { /* code */ } catch (ex Exception) { /* handle */ }
B. try { /* code */ } catch Exception ex { /* handle */ }
C. try { /* code */ } catch { Exception ex } { /* handle */ }