Put code between try, catch it runs very slow. Resource intensive. So just handle exceptions when they really needed. When is that? The exceptions are built to handle conditions that can not be controlled with the application logic. For example that drops the connection to the server, or the disk is full, or the hardware failed ... Before throwing exceptions for everything, let's look is really necessary. Avoid putting too much code in the try, try to deal only with code that can actually fail. For example is preferable:
Code:
if (con.State! = ConectionState.Closed)
{
con.Close ();
}
to:
try
{
con.Close ();
}
catch (InvalidOperationException exp)
{
Console.WriteLine (exp.GetType (). FullName);
Console.WriteLine (exp.Message);
}
Do not issue Exception (). Or is that it gives much information? The framework. Net has a number of exceptions that allow us to control arguments and invalid operations, timeouts, connections, overflows, etc. Let us use these exceptions really tell us what had happened.
Bookmarks