vbc builds an exception filter as a single non-short-circuiting
expression: `isinst`, then the user's `when` conditions, combined with
`and`. DetectCatchWhenConditionBlocks only knew the branch chain csc
emits, so the type test stayed inside the filter and the handler kept the
`object` variable it has in IL:
catch (object obj) when ((obj is Exception) & (num2 != 0) & (num == 0))
{
ProjectData.SetProjectError((Exception)obj);
A catch type has to derive from Exception, so that does not compile.
The conjunction form is matched too now, lifting the test to the catch
type as the block form already does. The other conjuncts stop running for
a non-matching exception once the test moves, so the filter has to be
pure for this to be invisible; PropagateExceptionVariable then drops the
castclass in the handler:
catch (Exception ex) when ((num2 != 0) & (num == 0))
{
ProjectData.SetProjectError(ex);
Closes #3659
18 lines
430 B
VB.net
18 lines
430 B
VB.net
Imports System
|
|
Public Class Issue3659
|
|
Public Shared Sub Func(ByRef obj As Issue3659, value As Object)
|
|
End Sub
|
|
|
|
Public Shared Function ShowMessage(a As String, b As Integer, c As String, d As Object, e As Integer) As Integer
|
|
Return 0
|
|
End Function
|
|
|
|
Friend Sub VBFunction(value As Object)
|
|
On Error GoTo Handler
|
|
Func(Me, value)
|
|
Exit Sub
|
|
Handler:
|
|
ShowMessage("VBFunction", 0, "Exception", Nothing, 0)
|
|
End Sub
|
|
End Class
|