+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:
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
ForA \
ForB \
ForEachB \
-LoopStatementsA
+LoopStatementsA \
+ExceptionHandlingA \
+ExceptionHandlingB
# All negetive test cases which should
# fail during compilation goes here
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