vb.net - How to customize InnerException.Message for System.Data.UpdateException in ASP.NET -
first of taking time read through post. have question may newbie piece of cake some.
i adding data database table using entity framework. when adding duplicate primary key exception in innerexception.message reads "violation of primary key constraint 'pk_studentid'. cannot insert duplicate key in object 'dbo.students'. statement has been terminated. "
however, want rephrase error message end user, save exact message table name , column name logs later. essentially, want rephrase error message "you cannot have duplicate entry student identification number. please enter new value."
how can this?
i have tried inherit system.data.updateexception , put if check see innerexception.message reads, , change accordingly. did not work.
thanks,
i think want.
try 'your code catch ex exception 'store ex.message want throw new exception("your custom message here.") end try
example:
private sub uifunction() dim errormessage string try 'a call bll function/sub cause exception catch ex exception errormessage = ex.message() 'ex.message() = "your custom message." end try end sub public sub bllfunction() try 'run code cause exception catch ex exception throw new exception("your custom message.") end try end sub
Comments
Post a Comment