Catching oracle procedure exception in a .NET C# application
634402Apr 16 2008 — edited Jan 27 2011In sql server 2000, I would catch sql error codes and throw a new message to the users? I was wondering (in oracle) what the error codes are and if anyone has a custom error message class for oracle 9i?
This is an example of the approach in SQL Server:
virtual public DataTable ExecuteDataTable() {
DataTable dt = null;
try {
Prepare ("ExecuteDataTable");
SqlDataAdapter a = new SqlDataAdapter(this.Command);
dt = new DataTable();
a .Fill(dt);
TraceResult ("# Rows in DataTable = " + dt.Rows.Count);
} catch (SqlException e) {
throw SomeExceptionFunction(e);
} finally {
CloseOpenedConnection ();
}
return dt;
}
protected Exception SomeExceptionFunction (SqlException ex) {
....... (code )
...... (code)
if (dalException == null) {
// uses SQLServer 2000 ErrorCodes
switch (ex.Number) {
case 17:
// SQL Server does not exist or access denied.
case 4060:
// Invalid Database
case 18456:
// Login Failed
dalException = new DalLoginException(ex.Message, ex);
break;
case 547:
// ForeignKey Violation
dalException = new DalForeignKeyException(ex.Message, ex);
break;
case 1205:
// DeadLock Victim
dalException = new DalDeadLockException(ex.Message, ex);
break;
case 2627:
case 2601:
// Unique Index/Constriant Violation
dalException = new DalUniqueConstraintException(ex.Message, ex);
break;
default:
// throw a general DAL Exception
dalException = new DalException(ex.Message, ex);
break;
}
}
// return the error
return dalException;
}