Bird
0
0

Given this pseudocode, what will be the output if the main service call fails?

medium📝 Analysis Q4 of 15
Microservices - Resilience Patterns
Given this pseudocode, what will be the output if the main service call fails? try { response = callMainService() } catch (Exception e) { response = fallbackResponse() } print(response) Assuming callMainService() throws an exception and fallbackResponse() returns "Backup Data".
A"Error"
B"Backup Data"
C"null"
D"Main Service Data"
Step-by-Step Solution
Solution:
  1. Step 1: Analyze try-catch behavior

    If callMainService() throws an exception, the catch block executes and assigns fallbackResponse() result to response.
  2. Step 2: Determine fallbackResponse() output

    fallbackResponse() returns "Backup Data", so response will be "Backup Data".
  3. Final Answer:

    "Backup Data" -> Option B
  4. Quick Check:

    Fallback triggers on exception = "Backup Data" [OK]
Quick Trick: Fallback runs on exception, returns backup data [OK]
Common Mistakes:
MISTAKES
  • Assuming main service data prints despite failure
  • Confusing exception with null response
  • Expecting error message printed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes