BestPromptFinder
HomeDebugging › Below is an instruction that describes a task. Write a respo...

Below is an instruction that describes a task. Write a respo...

Debugging · General · Coding
50Quality
90%Useful
87Reliability

The prompt

Below is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: Modify the following Python code to handle errors. ### Input: def read_data_from_json(filename): with open(filename, 'r') as f: data = json.load(f) return data ### Output: def read_data_from_json(filename): try: with open(filename, 'r') as f: data = json.load(f) return data except FileNotFoundError: print("The file specified does not exist.") except json.decoder.JSONDecodeError: print("The file specified is not in a valid JSON format.")
Find similar in the app →

Why this prompt

Source

Hugging Face

Related Debugging prompts

Bug Reproduction Detective
Quality 93 · Claude Code
Security-Focused Code Review
Quality 93 · Claude Code
Performance Bottleneck Optimizer
Quality 93 · Claude Code
Production Incident Root Cause
Quality 93 · Claude Code
Python Bug Triage Assistant
Quality 92 · Gemini, GPT-5.6, Claude
Code Review Assistant
Quality 90 · GPT-5.6