Updated: 10/13/2003; 9:20:37 PM.
John Lambert
First we show up, then we see what happens.
        

Wednesday, March 12, 2003

Here's the best VB.NET solution I could come up with: strong typing and the syntax is all 'inline' which was one of my problems with the filter one. (I'm starting to see how something like this might be useful for C#.)

    Public Shared Function CatchOnly(ByVal ex As Exception, ByVal ParamArray types As Type())

        Return Array.IndexOf(types, ex.GetType()) <> -1

    End Function

 

    Public Shared Sub TestThrow2(ByVal t As Exception)

        Try

            Console.WriteLine("Throwing: " & t.ToString())

            Throw t

        Catch ex As Exception When CatchOnly(ex, GetType(FooException), GetType(BarException))

            Console.WriteLine("Caught: " & ex.ToString())

        Catch ex As Exception

            Console.WriteLine("Didn't Catch: " & ex.ToString())

        Finally

            Console.WriteLine("Finally")

        End Try

    End Sub


2:08:36 AM    comment []  



© Copyright 2003 John Lambert jlambert@jlambert.com A really bad webcam picture of me.

 
March 2003
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Feb   Apr


Click here to visit the Radio UserLand website.

Subscribe to "John Lambert" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.