Exceptions caught within a loop

W

wildThought

I want to be able to catch an exception and KEEP PROCESSING with in
the try block. In my application, I may receive bad data in a
particular file line and want to keep processing the rest of the
file.

Is this possible?


try
{

while (engine.ReadNext() != null)
{
tmpCnt++;
record =
(LoanPerformance.Master)engine.LastRecord;
allData.Add(record);

// Your Code Here
}
}
catch(SomeException)
{

//Custom Exception Code

//How can I handle the exception so that the next
loop will iterate??????
}
 
A

Alberto Poblacion

wildThought said:
//How can I handle the exception so that the next
loop will iterate??????

Put the try...catch INSIDE the loop instead of surrounding the loop.
 
C

Christof Nordiek

Hi,
wildThought said:
I want to be able to catch an exception and KEEP PROCESSING with in
the try block. In my application, I may receive bad data in a
particular file line and want to keep processing the rest of the
file.

Is this possible?
You'll have to put the try-statement inside the loop.
try
{

while (engine.ReadNext() != null)
{
In this example, if you want to catch an exception from the ReadNext, you
will have to slightly redisign your loop. Something like:

whle(true)
{
try
{
if (engine.ReadNext() == null)
break;
}
catch (.....)
{
.....
if (cantProceed) break;
.....
}
......
}

Gruß
Christof
 
W

wildThought

Thanks for your help.

Hi,



You'll have to put the try-statement inside the loop.





In this example, if you want to catch an exception from the ReadNext, you
will have to slightly redisign your loop. Something like:

whle(true)
{
try
{
if (engine.ReadNext() == null)
break;


}
catch (.....)
{
.....
if (cantProceed) break;
.....
}
......

}

Gruß
Christof
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top