Skip error lines and process next line

Hi all,

I am importing journal lines from excel through code.

for ex. i’m having 15 line against a journal, while importing some error coming on 3 line

in try catch i’m getting error description and process terminated, i need to go with further lines 4th line by skip the error line 3

At the same time i need to know how much line having error

Thanks,

Can you show us your your catch clause, please?

Sorry Martiin, this is new requirement, I’m making RnD with some test job

In actual job

try

{

ttsbegin;

//logic

ttscommit;

}

catch (Exception::Error)
{
ttsAbort;

info(strFmt(“Error while creating the journal lines at line %1 from journal template details.”,lineNum));
}

Test job:

static void TryCatchJob(Args _args)
{
#OCCRetryCount

Exception excepnEnum;
int nCounter = 0;

try
{
for (nCounter = 1; nCounter <= 20; nCounter++)
{
if (nCounter == 3 || nCounter == 6 || nCounter == 8 || nCounter == 13 || nCounter == 18)
{
info(strFmt("%1 - %2", nCounter, “None” ));
}
else if (nCounter == 7 || nCounter == 9 || nCounter == 15 || nCounter == 16 || nCounter == 19)
{
info(strFmt("%1 - %2", nCounter, “Warning” ));
throw warning(“This warning will not be caught. " + int2str(nCounter));
}
else
{
info(strFmt(”%1 - %2", nCounter, “Error” ));
throw error(“This error message is written to the Infolog.” + int2str(nCounter));
}
}
}
catch (Exception::Error)
{
info(“Caught ‘Exception::Error’.”);
retry;
}
catch (Exception::Deadlock)
{
info(“Caught ‘Exception::Deadlock’.”);
// retry on deadlock
retry;
}
catch (Exception::UpdateConflict)
{
// try to resolve update conflict
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
catch(Exception::DuplicateKeyException)
{
// retry in case of an duplicate key conflict
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::DuplicateKeyExceptionNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::DuplicateKeyException;
}
}
}

Please look at the code above and as yourself if you it’s easy to read. It’s clearly not, because indentation is very important. Please make sure you use Insert > Insert Code next time.

Here is how it can look. Better, isn’t it?

try
{
	ttsbegin;

	//logic

	ttscommit;
}
catch (Exception::Error)
{
	ttsAbort;

	info(strFmt("Error while creating the journal lines at line %1 from journal template details.",lineNum));
}

Test job:

static void TryCatchJob(Args _args)
{
	#OCCRetryCount

	Exception excepnEnum;
	int nCounter = 0;

	try
	{
		for (nCounter = 1; nCounter <= 20; nCounter++)
		{
			if (nCounter == 3 || nCounter == 6 || nCounter == 8 || nCounter == 13 || nCounter == 18)
			{
				info(strFmt("%1 - %2", nCounter, "None" ));
			}
			else if (nCounter == 7 || nCounter == 9 || nCounter == 15 || nCounter == 16 || nCounter == 19)
			{
				info(strFmt("%1 - %2", nCounter, "Warning" ));
				throw warning("This warning will not be caught. " + int2str(nCounter));
			}
			else
			{
				info(strFmt("%1 - %2", nCounter, "Error" ));
				throw error("This error message is written to the Infolog." + int2str(nCounter));
			}
		}
	}
	catch (Exception::Error)
	{
		info("Caught 'Exception::Error'.");
		retry;
	}
	catch (Exception::Deadlock)
	{
		info("Caught 'Exception::Deadlock'.");
		// retry on deadlock
		retry;
	}
	catch (Exception::UpdateConflict)
	{
		// try to resolve update conflict
		if (appl.ttsLevel() == 0)
		{
			if (xSession::currentRetryCount() >= #RetryNum)
			{
				throw Exception::UpdateConflictNotRecovered;
			}
			else
			{
				retry;
			}
		}
		else
		{
			throw Exception::UpdateConflict;
		}
	}
	catch(Exception::DuplicateKeyException)
	{
		// retry in case of an duplicate key conflict
		if (appl.ttsLevel() == 0)
		{
			if (xSession::currentRetryCount() >= #RetryNum)
			{
				throw Exception::DuplicateKeyExceptionNotRecovered;
			}
			else
			{
				retry;
			}
		}
		else
		{
			throw Exception::DuplicateKeyException;
		}
	}
}

Regarding your “actual job”, do you get the info? If not, it means that your catch clause isn’t called at all, most likely because it’s inside a transaction. Also, remove ttsAbort - the transaction is already aborted when an exception is thrown.

Regarding your “test job”, most of the code does nothing - you can’t catch UpdateConflict exception, for example, if it’s never thrown. Also, don’t throw warnings and be very careful with retries. When you remove all dead code, you end up testing that you can catch Exception::Error. It’s fine, but trivial and it’s not going to help you or me with your problem.

Thanks Martin for your valuable answer.