Search code examples
npgsql

Code property on NpgsqlException


I'm trying to move from v2.0.11 of NPGSQL to v3.1.7 howeer in my code I am accessing the Code property of NpgsqlException. In 3.1.7 this has gone; how can I access the underlying code error from postgres now?


Solution

  • In Npgsql 3.1, PostgreSQL errors are thrown as PostgresException, not NpgsqlException (which is reserved for other errors, e.g. network issues). If you catch PostgresException, you'll find the SqlState property which has replaced Code (which still exists but is obsoleted).