The PostgreSql documentation does not seem to mention a special class range for custom error codes. Has any been defined or is there an unofficial agreement on a specific class range?
1 Answer
At the bottom of the first section on this page there is some oblique, and indeed rather unspecific, reference to custom error codes. My approach for custom error codes:
- Start with a capital letter but not F (predefined config file errors), H (fdw), P (PL/pgSQL) or X (internal).
- Do not use 0 (zero) or P in the 3rd column. Predefined error codes use these commonly.
- Use a capital letter in the 4th position. No predefined error codes have this.
As an example, start with a character for your app: "T". Then a two-char error class: "3G". Then a sequential code "A0"-"A9", "B0"-"B9", etc. Yields T3GA0, T3GA1, etc.
But as Craig Ringer indicated in his comment to the OP, some better guidance on the topic might be useful. Keep in mind though that such guidance would hardly solve the issue, unless a global registry is made of error ranges for common extensions. I am doubtful that such a registry will be made, however.
3 Comments
com.mycompany.myproject.ErrorCode. Which isn't possible with an SQLState.
SQLException#getErrorCode(), while PostgreSQL always return0from that method. I've looked pretty hard and found nothing discussing custom errors viaSQLException#getSQLState().