senzacionale
senzacionale

Reputation: 20906

custom exception and parsing message from exception

ex.Message = "ORA-20586: SOME TEXT SOME TEXT.\nORA-06512: at \"RMM.LOKAC\", line 116\nORA-06512: at line 2"

catch (Exception ex)
    MessageBox.Show(ex.Message);
    return false;
}

ex.Message = "ORA-20586: SOME TEXT SOME TEXT.\nORA-06512: at \"RMM.LOKAC\", line 116\nORA-06512: at line 2"

but i need to get just "SOME TEXT SOME TEXT". How can i read just text.

ORA-20586 means user error http://www.dbmotive.com/support/oracle-error-codes/?type=ORA&errcode=20586

Database is Oracle. How can i read just "SOME TEXT SOME TEXT" from this error message.

Upvotes: 0

Views: 1255

Answers (2)

user153923
user153923

Reputation:

It is always better to catch the exception, then write a more user friendly message. You never want to expose the underlying architecture of your application, if possible.

bool success = false;
try {
  // you code
  success = true; // Notice: Last call of  your try routine.
} catch (Exception ex {
  if (-1 < ex.Message.IndexOf("ORA-20586")) {
    MessageBox.Show("user error");
  } else {
    MessageBox.Show(ex.Message);
  }
}
return success;

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94645

There are number of ways to extract the string. You may try String split, regular expression split or string index search.

Upvotes: 2

Related Questions