Monday, October 6, 2008

"abort script" statement in "try...end try" blocks...


Syntactically, we cannot use the "abort script" statement inside a "try ... end try" block, which is a limitation (or may be for some logical reason) in Dex.

But most of the times, "abort script" is indeed a boon for most of the scenarios, where we need to skip the further processing of that particular script. How to overcome this?

We can simulate this "abort script" inside a "try ... end try". Check out the following code:

try
{regular code pieces}
if ProcessFurther = false then
throw EXCEPTION_ABORT_SCRIPT; {You can create this constant for reusability on your code with some integer value which you think is not used for any other System Exceptions}
else
{Proceed further}
end if;
catch
{Handle the Exceptions}
catch [EXCEPTION_ABORT_SCRIPT] {Your own Exception defined}
{Just do nothing. This is to simulate the "abort script" functionality.}
end try;

This is an easy way to simulate the "abort script" inside a "try ... end try" block.

Other possibilities are most welcome.

Vaidy

No comments:

Post a Comment

Blog has moved, searching new blog...