Long time I tried to catch only error message from oracle raise_application_error method. but every time error return with oracle error line no and code. I need to get error message only.
There is my Oracle query as belows :
IF totalAmony IS NOT NULL AND sumAmount IS NULL
THEN
RAISE_APPLICATION_ERROR(-20001, 'Account no cannot be blank');
END IF;
And my C# Code :
try
{
// somcode...;
}
catch (OracleException ex)
{
MessageBox.Show(lookAndFeelError, ex.Message, "Title", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
I need to show 'Account no cannot be blank' in Messagebox.
CodePudding user response:
You can depend on the Code
property of the exception object. So that in your question example you can check whether the exception code equals the exception you are looking for, if it is you can show the error message.
try
{
// somcode...;
}
catch (OracleException ex)
{
if(ex.Code == -20001) {
MessageBox.Show(lookAndFeelError, ex.Message, "Title", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}