Re: How to identify an error?
From: Tal (talg_at_nice.com)
Date: 06/10/04
- Next message: Mick Doherty: "Re: Uxtheme.dll skinning"
- Previous message: One Handed Man \( OHM#\): "Re: How to identify an error?"
- In reply to: DraguVaso: "How to identify an error?"
- Next in thread: DraguVaso: "Re: How to identify an error?"
- Reply: DraguVaso: "Re: How to identify an error?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 10 Jun 2004 11:49:58 +0300
Hi,
If it is SQL error, you may catch System.Data.SqlClient.SqlException instead
of Exception.
In SqlException, you are having several properties such as Number that give
you the specific error.
So in the client side you may want to do something like that:
catch (SqlException exp)
{
if (exp.Number == 1801)
do action;
else if (exp.Number == 1802)
do action2;
else WriteErrorMessage ("Fail to do this op, SQL error desription" +
exp.Message);
}
catch (Exception exp)
{
WriteErrorMessage ("Fail to do this op, error desription" +
exp.Message);
}
You may also define your excpetions and do the following in the server side:
catch (SqlException exp)
{
if (exp.Number == 1801)
throw new MyException1();
else if (exp.Number == 1802)
throw new MyException2();
else throw;
}
And in the client side catch those exceptions and do the needed actions.
It is not a good idea to have if statement on the message string.
"DraguVaso" <pietercoucke@hotmail.com> wrote in message
news:OlPwtMsTEHA.2464@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I want my application do different actions depending on the exception it
> gets.
> For exemple: I have an SQL-table with a unique index. In case I try to
> Insert a record that's alreaddy in it I get this exception: "Cannot insert
> duplicate key row in object 'tblTelephones' with unique index
> 'UniqueValues'."
>
> What I'm looking for is a way to identify the exception: in case I get
this
> exception I want to do this, in case of another I want to do that.
>
> The most simple solution to me seems this:
> Catch ex As Exception
> If Left(ex.Message, 41) <> "Cannot insert duplicate key row in
> object" Then
> 'do this action
> End If
>
> QAlthough, I'm not convinced this is the best way. Is there a way to
> identify the exception with a unique number? Or I've seen once something
> like a name for an error. Can anybody help me with this?
>
> Thanks a lot in advance
>
> Pieter
>
>
>
- Next message: Mick Doherty: "Re: Uxtheme.dll skinning"
- Previous message: One Handed Man \( OHM#\): "Re: How to identify an error?"
- In reply to: DraguVaso: "How to identify an error?"
- Next in thread: DraguVaso: "Re: How to identify an error?"
- Reply: DraguVaso: "Re: How to identify an error?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|