try to improve try..catch vs loops

This commit is contained in:
Jindra Petřík
2021-02-06 22:03:04 +01:00
parent 72f0c66aa7
commit 7644eddfd3
17 changed files with 559 additions and 384 deletions

View File

@@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'05.02.2021'</value>
<value>'06.02.2021'</value>
</define>
<define append="true">
<name>CONFIG::air</name>

View File

@@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'05.02.2021'</value>
<value>'06.02.2021'</value>
</define>
<define append="true">
<name>CONFIG::air</name>

View File

@@ -12,9 +12,12 @@ package
{
TestTryCatch;
TestTryCatchIfInTry;
TestTryCatchInIf;
TestTryCatchInWhile;
TestTryCatchInWhile2;
TestTryCatchInWhile3;
TestTryCatchLoop;
TestTryCatchLoopBreak;
TestTryCatchExceptionUsage
TestTryFinally;
TestTryFinallyDirectReturnInFinally;

View File

@@ -0,0 +1,29 @@
package tests
{
/**
* ...
* @author JPEXS
*/
public class TestTryCatchInIf
{
public function run() : int
{
var a:int = Math.random();
if (a > 10)
{
try
{
return 1;
}
catch(e:Error)
{
// ignore
}
}
return 2;
}
}
}

View File

@@ -0,0 +1,33 @@
package tests
{
import flash.errors.EOFError;
/**
* ...
* @author JPEXS
*/
public class TestTryCatchInWhile3
{
public function run() : String
{
var a:int;
a = 0;
trace("before loop");
while (a > 5)
{
try
{
return "intry return";
}
catch(e:Error)
{
trace("in catch");
}
a++;
}
return "OK";
}
}
}

View File

@@ -0,0 +1,74 @@
package tests
{
import flash.errors.EOFError;
/**
* ...
* @author JPEXS
*/
public class TestTryCatchLoopBreak
{
public function run() : void
{
var a:int;
a = 0;
trace("before loop");//1-15
try
{
trace("try1a");//16-22
while (a < 10){ //34-37 loop0
trace("a=" + a); //23-33
a++;
}
trace("try1b"); //38-44
//45-45
}
catch(e:Error)
{
trace("in catch"); //46-61
}
trace("middle");//62-68
while (a < 20) { //104-107 loop1
//69-69
try
{
trace("try2"); //70-77
return;
}
catch(e:Error)
{
trace("in catch2"); //80-103
}
trace("a=" + a); //pokračuje 80-103
}
trace("middle2"); //108-114
while (true) { //161-161 loop2
//115-115
try
{
trace("try3"); //116-122
}
catch(e:Error)
{
trace("in catch3"); //124-141
break;
}
catch(e:EOFError)
{
trace("in catch4"); //141-159
break;
}
//123-123
}
trace("exit"); //162-167
}
}
}