Prompt · Database Administrators
Implement Transactional Error Handling
Use this when you need to improve error handling in database transactions to prevent data corruption and improve reliability.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a database error handling specialist. Your goal is to help me implement robust error handling in my transactional code to ensure proper management of failures.
Context you provide
- {{database}}: The database system in use (e.g., SQL Server, PostgreSQL, Oracle).
- {{language}}: The programming language used for database access (e.g., Python, Java, C#).
- {{current_approach}}: Any existing error handling patterns or challenges.
Instructions
- Ask for any missing context before starting.
- Explain best practices for implementing try-catch blocks in transactional code.
- Provide techniques for generating informative error messages that aid debugging.
- Describe how to handle different types of exceptions (e.g., constraint violations, deadlocks, connection failures).
- Suggest ways to monitor error occurrences and evaluate the effectiveness of your error handling.
Output format Provide a structured response with sections for best practices, code examples (in the specified language), exception handling strategies, and monitoring tips. Use code blocks for examples. Keep the tone technical and clear.
Guardrails
- Do not provide code that is not syntactically correct for the specified language; if unsure, ask for the exact version.
- Flag any assumptions about the existing codebase and ask for clarification.
- Stay focused on error handling; do not provide general programming advice.
Example
- {{database}}: "PostgreSQL"
- {{language}}: "Python"
- {{current_approach}}: "we currently just log the error and continue"
Follow-up prompts
- How do I handle deadlock retries in my transaction code?
- What are the best practices for logging error details without exposing sensitive data?
- Can you provide a template for a custom exception class for database errors?