Link to home
Start Free TrialLog in
Avatar of fkmfkm
fkmfkm

asked on

More friendlier OleDb error message.

Instead of the error message

"The statement has been terminated. Violation of PRIMARY KEY....."

Is there anyway to trap different types of error (...primary key, length too long, unique constraint) and provide a nicer error message to the user.

How do you guys do it ? can share ?
Avatar of PockyMaster
PockyMaster
Flag of Netherlands image

Most of the time, these kind of things happen when you want to perform some kind of sequence of actions. E.g. a user tried to store a product he just designed.
Does he want to know a primary key was violated?
No, he wants to know just if his product was stored or not.
Your application might write the real message to a log or something like that. So in case your angry customer calls you, you have a way to sort it out :D

Avatar of Bob Learned
Try

Catch ex As OleDbException

  Throw New Exception("This is a better exception message")

End Try

Bob
Avatar of fkmfkm
fkmfkm

ASKER

Thanks Pocky and LearnedOne,

I guess the answer is the combination of both your suggestions.

TheLearnedOne,

Is there anyway to catch more specific error eg. Primary Key violation, Secondary ..etc ?

While this is not a comprehensive list, these are the data exception that I have found so far:

System.Data      ConstraintException
System.Data      DataException
System.Data      DBConcurrencyException
System.Data      DeletedRowInaccessibleException
System.Data      DuplicateNameException
System.Data      InRowChangingEventException
System.Data      InvalidConstraintException
System.Data      InvalidExpressionException
System.Data      MissingPrimaryKeyException
System.Data      NoNullAlllowedException
System.Data      ReadOnlyException
System.Data      RowNotInTableException
System.Data      StringTypingException
System.Data      TypedDataSetGeneratorException
System.Data      VersionNotFoundException
System.Data.OleDb      OleDbException

Bob
Avatar of fkmfkm

ASKER

Thanks TheLearnedOne,

A step closer now..

Ok with SQL I always have this problem. When my data exceeds the lenght of the field..I will get some error message .. The problem is I do not know which field is this that is exceeded.

So to make my problem more general..is there away (easy though) to highlight to there user some thing more specific like.."Data Address is too long" etc...Something so that the user knows how to rectify the problem himself.



Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial