better try..catch..finally detection

This commit is contained in:
Jindra Petřík
2021-01-31 09:13:36 +01:00
parent b2b9b51301
commit a1bb35ba1c
49 changed files with 1481 additions and 452 deletions

View File

@@ -0,0 +1,34 @@
package
{
import flash.display.MovieClip;
import flash.events.Event;
import tests.*;
/**
* ...
* @author JPEXS
*/
public class Main extends MovieClip
{
TestTryCatch;
TestTryCatchIfInTry;
TestTryCatchLoop;
TestTryCatchExceptionUsage
TestTryFinally;
TestTryFinallyDirectReturnInFinally;
TestTryFinallyLoop;
TestTryFinallyLoopInFinally;
TestTryFinallyMultipleCatch;
TestTryFinallyReturn;
TestTryFinallyReturnInFinally;
TestTryFinallyReturnNested;
TestTryFinallyReturnVoid;
public function Main()
{
}
}
}

View File

@@ -0,0 +1,26 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryCatch
{
public function run() : void
{
trace("before try");
try
{
trace("in try");
}
catch (e:Error)
{
trace("in catch");
}
trace("after");
}
}
}

View File

@@ -0,0 +1,26 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryCatchExceptionUsage
{
public function run() : void
{
trace("before try");
try
{
trace("in try");
}
catch (e:Error)
{
trace("catched exception: "+e.message);
}
trace("after");
}
}
}

View File

@@ -0,0 +1,32 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryCatchIfInTry
{
public function run() : void
{
var a:Boolean = true;
trace("before");
try
{
if (a)
{
trace("ret");
return;
}
trace("in try");
}
catch (e:Error)
{
trace("in catch");
}
trace("after");
}
}
}

View File

@@ -0,0 +1,39 @@
package tests
{
import flash.errors.EOFError;
/**
* ...
* @author JPEXS
*/
public class TestTryCatchLoop
{
public function run() : void
{
var j:* = undefined;
for (var i:* = 0; i < 100; i++)
{
try
{
for (j = 0; j < 20; j++)
{
trace("a");
}
}
catch (e:EOFError)
{
continue;
}
catch (e:Error)
{
continue;
}
trace("after_try");
}
trace("end");
}
}
}

View File

@@ -0,0 +1,30 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryFinally
{
public function run() : void
{
trace("before try");
try
{
trace("in try");
}
catch (e:Error)
{
trace("in catch");
}
finally
{
trace("in finally");
}
trace("after");
}
}
}

View File

@@ -0,0 +1,34 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryFinallyDirectReturnInFinally
{
public function run() : String
{
var str:String = "xxx";
try
{
}
catch (e:Error)
{
trace("error");
}
finally
{
trace("hi ");
if (5 == 4)
{
return str;
}
return "hu" + str;
}
}
}
}

View File

@@ -0,0 +1,38 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryFinallyLoop
{
public function run() : void
{
for (var i:int = 0; i < 10; i++)
{
trace("before try");
try
{
trace("in try");
if (i == 5)
{
trace("continue for");
continue;
}
}
catch (e:Error)
{
trace("in catch");
}
finally
{
trace("in finally");
}
trace("after");
}
}
}
}

View File

@@ -0,0 +1,38 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryFinallyLoopInFinally
{
public function run() : void
{
for (var i:int = 0; i < 10; i++)
{
trace("before try");
try
{
trace("in try");
}
catch (e:Error)
{
trace("in catch");
}
finally
{
if (i == 5)
{
trace("continue for");
continue;
}
trace("in finally");
}
trace("after");
}
}
}
}

View File

@@ -0,0 +1,35 @@
package tests
{
import flash.errors.EOFError;
/**
* ...
* @author JPEXS
*/
public class TestTryFinallyMultipleCatch
{
public function run() : void
{
trace("before try");
try
{
trace("in try");
}
catch (e:Error)
{
trace("in catch Error");
}
catch (e:EOFError)
{
trace("in catch EOFError");
}
finally
{
trace("in finally");
}
trace("after");
}
}
}

View File

@@ -0,0 +1,42 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryFinallyReturn
{
public function run() : String
{
trace("before try");
try
{
trace("in try");
var a:int = 5;
if (a > 4)
{
return "RET";
}
trace("between");
if (a < 3)
{
return "RE2";
}
trace("in try2");
}
catch (e:Error)
{
trace("in catch");
}
finally
{
trace("in finally");
}
trace("after");
return "RETFINAL";
}
}
}

View File

@@ -0,0 +1,44 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryFinallyReturnInFinally
{
public function run() : String
{
trace("before try");
try
{
trace("in try");
var a:int = 5;
if (a > 4)
{
return "RET";
}
}
catch (e:Error)
{
trace("in catch");
}
finally
{
trace("in finally");
if (a > 6){
return "FINRET1";
}
trace("xx");
if (a > 5){
return "FINRET2";
}
trace("nofinret");
}
trace("after");
return "RETEXIT";
}
}
}

View File

@@ -0,0 +1,43 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryFinallyReturnNested
{
public function run() : String
{
try
{
trace("before try2");
try
{
trace("in try2");
var a:int = 5;
if (a > 4)
{
return "RET";
}
}
catch (e:Error)
{
trace("in catch");
}
finally
{
trace("in finally2");
}
trace("after");
}
finally
{
trace("in finally1");
}
return "RETFINAL";
}
}
}

View File

@@ -0,0 +1,36 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryFinallyReturnVoid
{
public function run() : void
{
trace("before try");
try
{
trace("in try");
var a:int = 5;
if (a > 4)
{
return;
}
trace("in try2");
}
catch (e:Error)
{
trace("in catch");
}
finally
{
trace("in finally");
}
trace("after");
}
}
}