catch (OracleException e)
{
Cursor.Current = Cursors.Default;
_instance = null;
if (e.ErrorCode == -2147483648) // {"ORA-01017: invalid username/password; logon denied"}
{
throw new Exception("Nepravilno ime uporabnika ali geslo");
}
else
{
throw new Exception("Ne morem se povezati na podatkovno bazo. Preveri povezavo!");
}
}
but i always get Unhandled exception. Why?
At the risk of stating the obvious… Because you’re not catching the
Exceptionyou throw in your catch block? Or, perhaps, something else is being thrown in thetryblock that isn’t anOracleException.What are you expecting to happen?
Just to be totally clear (to make sure that we’re on the same page), an exception that’s thrown but never caught will result in an unhandled exception (by definition). Throwing an exception from within a
catchblock is identical to throwing it from anywhere else; there still needs to be atry-catchsomewhere to catch it. For example, this exception will be caught:But this one results in a new exception being propogated:
And this code catches both exceptions: