ExceptionTranslator

internal object ExceptionTranslator

Turns a server ErrorResponse into the exception the caller catches, choosing by SQLSTATE.

The distinction the whole hierarchy exists for is drawn here: a unique violation and a deadlock are things an application handles, a syntax error and a missing column are things it fixes, and they arrive as different types so that catch can tell them apart without reading a string. Where a code says nothing useful, UncategorizedDatabaseException carries it through with the server's own message rather than guessing at a category.

The mapping is by SQLSTATE class where PostgreSQL's classes are meaningful and by individual code where they are not — 40001 and 40P01 are both concurrency but want different reasons, and 57014 is a cancelled statement inside a class that is otherwise about the server being in trouble.

One distinction comes before the SQLSTATE, and it is the severity. A FATAL or a PANIC in an open session ends that session, whatever its code says, and goes through translateTermination; a FATAL at login is the server refusing one, and goes through translateRefusal. What reaches translate is always an ERROR.

Functions

Link copied to clipboard

The exception for errorMsg, an ERROR.

Link copied to clipboard

The exception for the ErrorResponse the server refused a login with.

Link copied to clipboard

The exception for a FATAL or PANIC the server sent in a session that was open.