TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mahesh Reddy
NA
363
17.1k
Display(Return) validation message in catch block
Jan 22 2019 10:52 PM
Hi,
In controller codei have used try and catch blocks
coming to my requirement
I have one model in that i have 2 fields named as Name,Code
In formi have entered only Name
after clicking of submitbutton it was throwing error
everything is ok
problem is that instead of displaying a cutsom error message in catch i need to display what type of exception raised in database
Could please kindly any one help me
Note:ifi can fill all the fields at that time it was saving to database properly
In catch block instead of displaying something went wrong display what type of exception we raised.
Code
............
try
{
State state = new State();
state.Name = Name;
state.Code = st.Code;
db.State.Add(state);
db.SaveChanges();
dbContextTransaction.Commit();
}
catch (Exception)
{
dbContextTransaction.Rollback();
return "Something went wrong";
}
Reply
Answers (
5
)
C# WCF Service - Need to restrict to specific host name
How to change connection string in Asp.Net