
@Amatya sir,
While writing a piece of code, there might be some logical errors that we may not predict. In that case if we run the program though it will compile and work in the best fit, but will fail in the exception scenarios. E.g.
int x = 50;
int y = 10;
int z = x/y;
the output is 5. This is the best case scenario.
But what about y=0;
You will encounter Divide by zero exception.
This scenarios cannot be caught until runtime.
Henceforth, as a best practice, we use Try..Catch block. e.g.
try {
int x = 50;
int y = 0;
int z = x/y;
}catch(DivideByZeroException ex) {Console.WriteLine(ex.message); } //for specific exception
catch(Exception e) { Console.Writeline(e.message);} //for any other kind of exceptions.
You can also refer to this (
http://www.dotnetfunda.com/articles/show/3185/generate-pdf-and-send-as-attachment-in-email-using-itextsharp-and-exce ) article of mine for more understanding so using the same.
Let us know if that helps.
--
Thanks & Regards,
RNA Team
Amatya, if this helps please login to Mark As Answer. | Alert Moderator