C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How To catch exception ,find the exception number


Posted Date: 17 Apr 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Ajay GuptaMember Level: Silver    
Rating: Points: 8



To catch exception ,find the exception number

Then finally based on number , ie by putting conditional statement , i want
to display error message.

Code goes like this:

private static Exception STSThrowSqlException(SqlException ex)
{
Exception STSsqlException = new Exception();
switch (ex.Number)
{
case -2:
{
STSsqlException = new
Exception(STSWebConstants.STS_RequestTimeOut);//Connection timeout
break;
}
case 18456:
case 1326:
{
STSsqlException = new
Exception(STSWebConstants.STS_LoginFailed);//login failed
break;
}
case 4060:
{
STSsqlException = new
Exception(STSWebConstants.STS_DataBaseNotAvailable);//if database is not
found
break;
}
case 229:
{
STSsqlException = new
Exception(STSWebConstants.STS_LoginCredentials);//login credentials check
break;
}

case 2601:
case 2627:
{
STSsqlException = new
Exception(STSWebConstants.STS_UniqueKeyConstraint);//unique key voilation
break;
}
case 547:
{
STSsqlException = new
Exception(STSWebConstants.STS_ForeignKeyConstraint);//Foreign Key
voilation.
break;
}
default:
{
STSsqlException = new
Exception(STSWebConstants.STS_UnKnowException);//any other exceptions
break;
}
}
return STSsqlException;
}







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Return all positions of a string in a string
Previous Resource: Email ID validation using regular expressions
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use