How to handle exception in c#

Posted by Sahoo under ASP.NET on 4/15/2013 | Points: 10 | Views : 2111 | Status : [Member] | Replies : 1
Hi All,

How to handle exception properly ?
Let say I am logging exception details to a text file on exception.But while writing exception details if file path not exist/some other exception occur how can I manage it.

How to handle exception if it happens in exception logging method.

Thanks




Responses

Posted by: Suwarna on: 4/15/2013 [Member] Starter | Points: 25

Up
0
Down
HI ..
For single try you can write many catch blocks. first catch should specific handle specific exception.You can handle generic exception in second catch block
If you want to handle file not exist exception and want to handle another exception then you can write code in following way
ry
{
System.IO.FileStream content = System.IO.File.Open("c:\\test.txt", System.IO.FileMode.Open);
}
catch (System.IO.FileNotFoundException EX)
{
throw;
}
catch (Exception EX)

{
throw;
}


Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response