How to execute inner catch in a transaction

Hi All,

I am at facing problem for below case with try catch, can any one please help me.

public static void methodA()

{

try

{

ttsbegin;

… code 1 …

methodB()

… code 2 …

ttscommit;

}

catch

{

warning (“outermost catch”);

}

}

public void methodB()

{

while select tableX

{

try

{

ttsbegin;

… code 3 …

if (! tableX.field)

{

throw error (“no valid data for: %1”, tablex.number") ;

}

… code 4…

ttscommit;

}

catch

{

warning (“innermost catch”);

}

}

…code 5…

…code 6…

}

When methodB is called, if the validation failed for tableX data, when outer most catch() is calling, but here I want to call the inner most catch because I have to loop through all the records in the while loop in method B.

Note: if I comment the ttsbegin and ttscommit in methodA then outermost catch (catch in methodA) is never executing, because of this some data is not reversing when code (… code 2 …) throws an error.

Can any one please help me out to catch Inner catch I my case.

Thanks in advance,

Satish

This is by design; it’s how X++ works. If you don’t trust me, consult Exception Handling with try and catch Keywords on MSDN.

Therefore your implementation will never work as you intended. You’ll have to redesign your solution so it doesn’t try to catch exceptions inside the transaction.

Maybe you can simply avoid throwing errors. This is an example of how methodB() could be redesigned:

public void methodB()
{
	while select tableX
	{
		... code 3 ...

		if (tableX.field)
		{
			... code 4...
		}
		else
		{
			warning ("No valid data for: %1",  tableX.number);
			... logic formerly in the innermost catch ...
		}
	
	}

	... code 5 ...
	... code 6 ...
}

If you have to throw an exception, you have to move all your exception handling to the outermost catch block.