Challenge - 5 Problems
Error Handling Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of error handling in a tool call
What is the output of this code snippet that calls a tool and handles errors?
Agentic AI
def call_tool(tool, input_data): try: result = tool(input_data) return f"Success: {result}" except ValueError: return "ValueError caught" except Exception: return "General error caught" def sample_tool(x): if x < 0: raise ValueError("Negative input") elif x == 0: raise RuntimeError("Zero input") else: return x * 2 output = call_tool(sample_tool, 0) print(output)
Attempts:
2 left
💡 Hint
Think about which exception is raised and which except block catches it.
✗ Incorrect
The tool raises RuntimeError when input is 0. The call_tool function catches ValueError separately, but RuntimeError is caught by the general Exception block, so it returns 'General error caught'.
❓ Model Choice
intermediate2:00remaining
Choosing the right error handling model for tool calls
Which error handling model is best suited for a tool call that may raise multiple specific exceptions and needs to log errors distinctly?
Attempts:
2 left
💡 Hint
Consider clarity and specific error handling needs.
✗ Incorrect
Using multiple try-except blocks for specific exceptions allows distinct handling and logging of each error type, improving clarity and debugging.
🔧 Debug
advanced2:00remaining
Identify the error in this tool call error handling code
What error will this code raise when calling the tool with input 5?
Agentic AI
def tool(x): if x == 5: raise KeyError("Key missing") return x def call_tool(tool_func, val): try: return tool_func(val) except ValueError: return "Value error handled" except KeyError: return "Key error handled" except: return "Other error" result = call_tool(tool, 5) print(result)
Attempts:
2 left
💡 Hint
Check which except block matches the raised exception.
✗ Incorrect
The tool raises KeyError for input 5, which is caught by the except KeyError block returning 'Key error handled'.
❓ Hyperparameter
advanced2:00remaining
Choosing retry count for error handling in tool calls
If a tool call fails due to a transient network error, which retry count is most reasonable to balance responsiveness and robustness?
Attempts:
2 left
💡 Hint
Too many retries can cause delays; too few may miss recovery.
✗ Incorrect
One retry balances quick failure with a chance to recover from transient errors without long delays.
🧠 Conceptual
expert3:00remaining
Best practice for error handling in asynchronous tool calls
Which approach best ensures error handling in asynchronous tool calls to avoid silent failures?
Attempts:
2 left
💡 Hint
Think about where errors can be caught in async code.
✗ Incorrect
Using try-except inside async functions allows catching and logging errors immediately, preventing silent failures.