Click here to Skip to main content
15,917,709 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to send password value securly Pin
Not Active9-Jan-07 17:40
mentorNot Active9-Jan-07 17:40 
AnswerRe: How to send password value securly Pin
Russell Jones9-Jan-07 22:27
Russell Jones9-Jan-07 22:27 
QuestionError handling Pin
Harikrk9-Jan-07 15:43
Harikrk9-Jan-07 15:43 
AnswerRe: Error handling Pin
Paul Conrad9-Jan-07 16:03
professionalPaul Conrad9-Jan-07 16:03 
AnswerRe: Error handling Pin
Christian Graus9-Jan-07 16:04
protectorChristian Graus9-Jan-07 16:04 
GeneralRe: Error handling Pin
JoeRip9-Jan-07 18:12
JoeRip9-Jan-07 18:12 
GeneralRe: Error handling Pin
JoeRip9-Jan-07 18:25
JoeRip9-Jan-07 18:25 
GeneralRe: Error handling Pin
Scott Dorman9-Jan-07 18:33
professionalScott Dorman9-Jan-07 18:33 
JoeRip wrote:
how do you compare exceptions?


You don't really compare exceptions. If you need to take different action based on different exceptions, you would write multiple catch handlers.

C#
try
{
   // do some code
}
catch (System.NullReferenceException)
{
   // do cleanup for handling a null reference
}
catch (System.InvalidOperationException)
{
   // do some other cleanup
}

The only caution is that you need to pay attention to the ordering of the catch handlers. The runtime will go through the catch handlers until it finds the first one that can handle the exception and then stop. This means that if you catch a base exception before a derived one, you will never handle the derived exception. For example:

C#
try
{
   // do some code that throws an ArgumentNullException
}
catch (System.ArgumentException)
{
   // do cleanup for handling a general argument exception
}
catch (System.ArgumentNullException)
{
   // this handler will never be run
}
 
try
{
   // do some code that throws an ArgumentNullException
}
catch (System.ArgumentNullException)
{
   // this handler will be run
}
catch (System.ArgumentException)
{
   // do cleanup for handling a general argument exception
}

In general, you only want to catch exceptions that your code can actually do something about and perform some sort of cleanup. You don't want to use them to help control your program flow as actually catching the exception is expensive.



-----------------------------
In just two days, tomorrow will be yesterday.

GeneralRe: Error handling Pin
Christian Graus9-Jan-07 18:42
protectorChristian Graus9-Jan-07 18:42 
GeneralRe: Error handling Pin
Martin Sp.10-Jan-07 3:41
Martin Sp.10-Jan-07 3:41 
QuestionTree View and Database Pin
64-bit9-Jan-07 14:49
64-bit9-Jan-07 14:49 
AnswerRe: Tree View and Database Pin
Judah Gabriel Himango9-Jan-07 15:42
sponsorJudah Gabriel Himango9-Jan-07 15:42 
GeneralRe: Tree View and Database Pin
64-bit9-Jan-07 17:35
64-bit9-Jan-07 17:35 
GeneralRe: Tree View and Database Pin
Judah Gabriel Himango9-Jan-07 17:37
sponsorJudah Gabriel Himango9-Jan-07 17:37 
QuestionWhy is my app using so much memory? Pin
Anthony Mushrow9-Jan-07 11:51
professionalAnthony Mushrow9-Jan-07 11:51 
AnswerRe: Why is my app using so much memory? Pin
Luc Pattyn9-Jan-07 11:58
sitebuilderLuc Pattyn9-Jan-07 11:58 
GeneralRe: Why is my app using so much memory? Pin
Anthony Mushrow9-Jan-07 12:01
professionalAnthony Mushrow9-Jan-07 12:01 
GeneralRe: Why is my app using so much memory? Pin
Luc Pattyn9-Jan-07 12:06
sitebuilderLuc Pattyn9-Jan-07 12:06 
AnswerRe: Why is my app using so much memory? Pin
DavidNohejl9-Jan-07 12:11
DavidNohejl9-Jan-07 12:11 
AnswerRe: Why is my app using so much memory? Pin
Christian Graus9-Jan-07 12:15
protectorChristian Graus9-Jan-07 12:15 
AnswerRe: Why is my app using so much memory? Pin
Anthony Mushrow9-Jan-07 12:24
professionalAnthony Mushrow9-Jan-07 12:24 
Questioncrystal reports vs MSSQL 2000 server Reporting services Pin
samuelred9-Jan-07 10:39
samuelred9-Jan-07 10:39 
QuestionBooks on OOPS and C# Pin
Blumen9-Jan-07 8:22
Blumen9-Jan-07 8:22 
AnswerRe: Books on OOPS and C# Pin
led mike9-Jan-07 9:25
led mike9-Jan-07 9:25 
GeneralWhile I like Wrox publishing Pin
Ennis Ray Lynch, Jr.9-Jan-07 13:34
Ennis Ray Lynch, Jr.9-Jan-07 13:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.