Added new tests for Exception Handling Statements
authorSachin Kumar <sachin@mono-cvs.ximian.com>
Thu, 26 Aug 2004 09:24:50 +0000 (09:24 -0000)
committerSachin Kumar <sachin@mono-cvs.ximian.com>
Thu, 26 Aug 2004 09:24:50 +0000 (09:24 -0000)
svn path=/trunk/mcs/; revision=32872

13 files changed:
mcs/btests/ChangeLog
mcs/btests/ExceptionHandlingA.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingB.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC1.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC2.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC3.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC4.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC5.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC6.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC7.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC8.vb [new file with mode: 0644]
mcs/btests/ExceptionHandlingC9.vb [new file with mode: 0644]
mcs/btests/Test.Sources

index b3e80d54f56c2983b969275b63bbaf8165b72ec0..d9e5654c662fec8ca4a6a381d7ffc14743f80185 100644 (file)
@@ -1,3 +1,17 @@
+2004-08-26 Sachin Kumar <skumar1@novell.com>
+       * ExceptionHandlingA.vb:
+       * ExceptionHandlingB.vb:
+       * ExceptionHandlingC1.vb:
+       * ExceptionHandlingC2.vb:
+       * ExceptionHandlingC3.vb:
+       * ExceptionHandlingC4.vb:
+       * ExceptionHandlingC5.vb:
+       * ExceptionHandlingC6.vb:
+       * ExceptionHandlingC7.vb:
+       * ExceptionHandlingC8.vb:
+       * ExceptionHandlingC9.vb:
+       * Test.Sources: included new tests
+
 2004-08-26 Anirban Bhattacharjee <banirban@novell.com>
        Following tests are submtted by Manish Sinha <manishkumarsinha@sify.com>
        * Arguments_ByValueA:
diff --git a/mcs/btests/ExceptionHandlingA.vb b/mcs/btests/ExceptionHandlingA.vb
new file mode 100644 (file)
index 0000000..0d51ce8
--- /dev/null
@@ -0,0 +1,81 @@
+Imports System\r
+\r
+Module ExceptionHandlingA\r
+\r
+    Sub Main()\r
+\r
+        ' Finally block is executed regardless of how execution \r
+        ' leaves the Try statement\r
+\r
+        ' Case 1: through the end of Try block\r
+        Dim i As Integer = 0\r
+        Try\r
+            i = i + 1\r
+        Finally\r
+            i = i + 2\r
+        End Try\r
+\r
+        If i <> 3 Then\r
+            Throw New Exception("#EHA1 - Finally block not executed")\r
+        End If\r
+\r
+        ' Case 2: through the end of Catch block\r
+        Try\r
+            i = i / 0\r
+        Catch e As Exception\r
+            i = i * 2\r
+        Finally\r
+            i = i * 3 / 2\r
+        End Try\r
+\r
+        If i <> 9 Then\r
+            Throw New Exception("#EHA2 - Finally block not executed")\r
+        End If\r
+\r
+        ' Case 3: through an Exit Try statement\r
+        Try\r
+            i = i / 9 * 2\r
+            Exit Try\r
+        Catch e As Exception\r
+            Console.WriteLine(e.Message)\r
+        Finally\r
+            i = i / 2\r
+        End Try\r
+\r
+        If i <> 1 Then\r
+            Throw New Exception("#EHA3 - Finally block not executed")\r
+        End If\r
+\r
+        ' Case 4: through a GoTo statement\r
+        Try\r
+            i = i - 1\r
+            GoTo label\r
+        Catch e As Exception\r
+            Console.WriteLine(e.Message)\r
+        Finally\r
+            i = i + 1\r
+        End Try\r
+label:\r
+        If i <> 1 Then\r
+            Throw New Exception("#EHA4 - Finally block not executed")\r
+        End If\r
+\r
+        ' Case 5: by not handling a thrown exception\r
+        Try\r
+            Try\r
+                i = 5\r
+                Throw New Exception("EE")\r
+            Finally\r
+                i = i * 5\r
+            End Try\r
+        Catch e As Exception\r
+            i = i * 2\r
+        End Try\r
+\r
+        If i <> 50 Then\r
+            Throw New Exception("#EHA5 - Finally block not exceuted")\r
+        End If\r
+\r
+    End Sub\r
+\r
+End Module
\ No newline at end of file
diff --git a/mcs/btests/ExceptionHandlingB.vb b/mcs/btests/ExceptionHandlingB.vb
new file mode 100644 (file)
index 0000000..88a42ab
--- /dev/null
@@ -0,0 +1,26 @@
+Imports System\r
+\r
+Module ExceptionHandlingB\r
+    Dim i As Integer\r
+    Sub Main()\r
+\r
+        Try\r
+\r
+            Try\r
+                i = 2 / i\r
+                i = 3\r
+                Console.WriteLine(i)\r
+            Catch e As Exception\r
+                Console.WriteLine(e.Message)\r
+                ' Try statement wil not handle any exceptions thrown in Catch block\r
+                Throw New Exception("FF")\r
+            End Try ' inner try\r
+\r
+            ' Catch exception thrown by inner Try statement \r
+        Catch e As Exception When e.Message = "FF"\r
+            Console.WriteLine("OK")\r
+        End Try  ' outer try\r
+    End Sub\r
+\r
+End Module\r
+\r
diff --git a/mcs/btests/ExceptionHandlingC1.vb b/mcs/btests/ExceptionHandlingC1.vb
new file mode 100644 (file)
index 0000000..f3744c8
--- /dev/null
@@ -0,0 +1,18 @@
+REM LineNo: 12\r
+REM ExpectedError: BC30441\r
+REM ErrorMessage: 'Catch' must end with a matching 'End Try'\r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC1\r
+\r
+    Sub Main()\r
+        Try\r
+            'Do something\r
+        Catch e As Exception\r
+            Console.WriteLine(e.Message)\r
+\r
+    End Sub\r
+\r
+End Module\r
+\r
diff --git a/mcs/btests/ExceptionHandlingC2.vb b/mcs/btests/ExceptionHandlingC2.vb
new file mode 100644 (file)
index 0000000..02f95d4
--- /dev/null
@@ -0,0 +1,14 @@
+REM LineNo: 9\r
+REM ExpectedError: BC30030\r
+REM ErrorMessage: Try must have atleast one 'Catch' or a 'Finally' \r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC2\r
+    Sub Main()\r
+        Try\r
+            Console.WriteLine("Exception in Main")\r
+        End Try\r
+    End Sub\r
+End Module\r
+\r
diff --git a/mcs/btests/ExceptionHandlingC3.vb b/mcs/btests/ExceptionHandlingC3.vb
new file mode 100644 (file)
index 0000000..f7cc4bb
--- /dev/null
@@ -0,0 +1,17 @@
+REM LineNo: 11\r
+REM ExpectedError: BC30380\r
+REM ErrorMessage: 'Catch' cannot appear outside a 'Try' statement.\r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC3\r
+\r
+    Sub Main()\r
+\r
+        Catch e As Exception\r
+            Console.WriteLine(e.Message)\r
+        End Try\r
+    End Sub\r
+\r
+End Module\r
+\r
diff --git a/mcs/btests/ExceptionHandlingC4.vb b/mcs/btests/ExceptionHandlingC4.vb
new file mode 100644 (file)
index 0000000..ac9811e
--- /dev/null
@@ -0,0 +1,15 @@
+REM LineNo: 9\r
+REM ExpectedError: BC30665\r
+REM ErrorMessage: 'Throw' operand must derive from 'System.Exception'\r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC4\r
+\r
+    Sub Main()\r
+        Dim i As Integer\r
+        Throw i\r
+    End Sub\r
+\r
+End Module\r
+\r
diff --git a/mcs/btests/ExceptionHandlingC5.vb b/mcs/btests/ExceptionHandlingC5.vb
new file mode 100644 (file)
index 0000000..185e06a
--- /dev/null
@@ -0,0 +1,30 @@
+REM LineNo: 13\r
+REM ExpectedError: BC30754\r
+REM ErrorMessage: 'Goto label1' is not valid because 'label1' is inside a 'Try',\r
+REM               'Catch' or 'Finally' statement that does not contain this statement.\r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC5\r
+    Dim i As Integer\r
+    Sub Main()\r
+        Dim i As Integer = 0\r
+\r
+        GoTo label1\r
+\r
+        Try\r
+            i = 1 / i\r
+label1:     ' do something here\r
+            i = 2 * i\r
+            GoTo label2\r
+        Catch e As Exception\r
+label2:\r
+            Console.WriteLine("Exception in Main: " & e.Message)\r
+            GoTo label3\r
+        Finally\r
+label3:\r
+            i = i + 2\r
+        End Try\r
+    End Sub\r
+\r
+End Module
\ No newline at end of file
diff --git a/mcs/btests/ExceptionHandlingC6.vb b/mcs/btests/ExceptionHandlingC6.vb
new file mode 100644 (file)
index 0000000..67eb912
--- /dev/null
@@ -0,0 +1,25 @@
+REM LineNo: 18\r
+REM ExpectedError: BC30451\r
+REM ErrorMessage: Name 'j' is not declared\r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC6\r
+\r
+    Sub Main()\r
+        Dim i As Integer\r
+        Try\r
+            Dim j As Integer = 2\r
+            i = j / i\r
+            i = 3\r
+            Console.WriteLine(i)\r
+        Catch e As Exception When i = 0\r
+            j = 3    ' Local varables from a Try block are not available in Catch block\r
+            Console.WriteLine(e.Message)\r
+        Finally\r
+            j = 4    ' Local varables from a Try block are not available in Finally block\r
+        End Try\r
+    End Sub\r
+\r
+End Module\r
+\r
diff --git a/mcs/btests/ExceptionHandlingC7.vb b/mcs/btests/ExceptionHandlingC7.vb
new file mode 100644 (file)
index 0000000..e301c62
--- /dev/null
@@ -0,0 +1,19 @@
+REM LineNo: 13\r
+REM ExpectedError: BC30201\r
+REM ErrorMessage: Expression expected\r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC7\r
+\r
+    Sub Main()\r
+        Dim i As Integer\r
+        Try\r
+            i = 1 / i\r
+        Catch e As Exception When\r
+            Console.WriteLine(e.Message)\r
+        End Try\r
+    End Sub\r
+\r
+End Module\r
+\r
diff --git a/mcs/btests/ExceptionHandlingC8.vb b/mcs/btests/ExceptionHandlingC8.vb
new file mode 100644 (file)
index 0000000..663e577
--- /dev/null
@@ -0,0 +1,19 @@
+REM LineNo: 14\r
+REM ExpectedError: BC30442\r
+REM ErrorMessage: 'Finally' must end with a matching 'End Try'\r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC8\r
+\r
+    Sub Main()\r
+\r
+        Dim i As Integer = 0\r
+        Try\r
+            i = 1 / i\r
+        Finally\r
+\r
+    End Sub\r
+\r
+End Module\r
+\r
diff --git a/mcs/btests/ExceptionHandlingC9.vb b/mcs/btests/ExceptionHandlingC9.vb
new file mode 100644 (file)
index 0000000..12dbcdf
--- /dev/null
@@ -0,0 +1,22 @@
+REM LineNo: 16\r
+REM ExpectedError: BC30384\r
+REM ErrorMessage: 'Try' must end with a matching 'End Try'\r
+\r
+REM LineNo: 16\r
+REM ExpectedError: BC30030\r
+REM ErrorMessage: Try must have at least one 'Catch' or a 'Finally'\r
+\r
+Imports System\r
+\r
+Module ExceptionHandlingC9\r
+\r
+    Sub Main()\r
+\r
+        Dim i As Integer = 0\r
+        Try\r
+            i = 1 / i\r
+\r
+    End Sub\r
+\r
+End Module\r
+\r
index 51d97adaf5577d94c646087517d2c53cbff91504..782a1a52d28e3dea13afad8a0864f114ff67c0aa 100644 (file)
@@ -214,7 +214,9 @@ ConditionalStatementsD \
 ForA \
 ForB \
 ForEachB \
-LoopStatementsA
+LoopStatementsA \
+ExceptionHandlingA \
+ExceptionHandlingB
 
 # All negetive test cases which should
 # fail during compilation goes here
@@ -458,7 +460,16 @@ ForEachC4 \
 ForEachC5 \
 ForEachC6 \
 ForEachC7 \
-ForEachC8
+ForEachC8 \
+ExceptionHandlingC1 \
+ExceptionHandlingC2 \
+ExceptionHandlingC3 \
+ExceptionHandlingC4 \
+ExceptionHandlingC5 \
+ExceptionHandlingC6 \
+ExceptionHandlingC7 \
+ExceptionHandlingC8 \
+ExceptionHandlingC9
 
 # All negetive test cases which should fail at
 # runtime goes here