I need to read different types of .txt files and for that I first read the first few lines where is the heading situated. With that information I'm able to select the way of reading it. The problem is that if only one record are in different format (say I substring(0,45)
and there are only 40 characters) my application crashes. I want to avoid this, but I can't check every possibility. I've read that you should avoid use too much try/catch, and I'm only using it when I don't know where the error could come from.
My question is: it is bad to use try/catch in a loop (30k - 40k times)?
If it's not, how can I use it properly? I don't understand completely the purpose of exceptions. Are they only for debugging? If not, what differences are between throw new exception
and MessageBox.Show("Error")
.
If I don't notify about the error and just skip it could I write something like this:
try
{
//problematic code
}
catch
{
//nothing
//continue;
}