Learning Objectives
By the end of this lesson you will be able to:
- Identify whether an error originated in the application layer or the database layer
- Read error signatures that distinguish the two failure sources
- Write a bug report that correctly identifies the failure layer
Why the Distinction Matters
When you find a bug, your job isn't just to say "it's broken." It's to give the developer enough information to fix it efficiently.
"The page returns a 500 error" sends the developer on a hunt. "The 500 error contains a PostgreSQL 'integer out of range' exception, indicating the overflow occurs at the database INSERT layer — not in the application code" tells the developer exactly where to look.
The fix is different depending on the layer:
- Application layer: validate input before passing to DB
- Database layer: the column type may need to be changed (INT → BIGINT)
Recognizing Application Layer Errors
Application errors occur when the server-side code crashes before or after the database call:
HTTP/1.1 500 Internal Server Error
{"error": "ArithmeticException: / by zero",
"trace": "at CalculationService.divide(CalculationService.java:47)"}
Signatures:
- Stack trace shows Java/Python/C# class names and method names
- Error type is a language-level exception (
NullPointerException,ZeroDivisionError) - The database is not mentioned at all
Recognizing Database Layer Errors
Database errors occur when the application attempts a query and the DB rejects it:
HTTP/1.1 500 Internal Server Error
{"error": "DataAccessException",
"cause": "ERROR: integer out of range",
"detail": "Detail: Value 3000000000 is out of range for type integer"}
or
{"error": "PSQLException: ERROR: division by zero"}
Signatures:
- Error message uses SQL or database-specific language
- Mentions specific database error codes (PostgreSQL:
22003, MySQL:1264) - Stack trace includes JDBC, JPA, Hibernate, or similar database driver classes
- Error type is
PSQLException,SQLException,DataAccessException
The Error Layer Decision Tree
Error received
↓
Does the stack trace mention Java/Python application classes?
Yes → Application Layer
No
↓
Does the error message mention SQL, PostgreSQL, integer, column, or table?
Yes → Database Layer
No
↓
Ambiguous — report both possibilities
Common Error Signatures Quick Reference
| Error Text | Layer | Meaning |
|---|---|---|
ArithmeticException: / by zero |
Application | Division by zero in app code |
NullPointerException |
Application | Null dereference in app code |
PSQLException: integer out of range |
Database | Value too large for INT column |
PSQLException: division by zero |
Database | Division by zero in SQL query |
ERROR: numeric field overflow |
Database | Value exceeds NUMERIC column precision |
DataIntegrityViolationException |
Database (via app) | Constraint violation (FK, NOT NULL, unique) |
Pro Tip: When you see
DataAccessExceptionorPersistenceExceptionin the stack trace, that's a Java wrapper around a database error. Look at thecauseordetailfield in the response — the actual database error is usually there.
Key Takeaways
- Application errors: Java/Python exception names in stack trace, no DB mentioned
- Database errors: SQL language, database exception types (PSQLException, SQLException)
- The fix differs by layer: validate before DB (app fix) vs. change column type (DB fix)
- Include the specific error type in your bug report — it tells the developer the layer immediately