I have a try block in my C# client which executes an Oracle PL/SQL stored procedure and a catch block using Exception class.
In the stored procedure, if a particular condition is encountered during data processing, an exception is raised using raise_application_error.
Example: raise_application_error(-20001, myErrMsg)
I then want to catch this exception and show this particular message in the C# client as it is.
And for all the other database related errors (e.g. constraint failure, connection errors) I want to catch and them show in my custom error message in the C# client.
In my catch block, should I search for the string ORA-20001 in the exception message string and then propagate it to the client as it is to determine if the above exception is being thrown from the procedure?
Catch an Oracle Exception if you can.
In the catch handler, check to see if the number is 20001, and then take appropriate action.
Here are some properties of OracleException
DataSource
Specifies the TNS name that contains the information for connecting to an Oracle instance
Errors
Specifies a collection of one or more OracleError objects that contain information about
exceptions generated by the Oracle database
InnerException
Inherited from Exception
Message
Specifies the error messages that occur in the exception
Number
Specifies the Oracle error number
Procedure
Specifies the stored procedure that cause the exception
Source
Specifies the name of the data provider that generates the error
StackTrace
Inherited from Exception
TargetSite
Inherited from Exception
Link For More Info:
http://download.oracle.com/docs/cd/B19306_01/win.102/b14307/OracleExceptionClass.htm