Results 1 to 5 of 5

Thread: [RESOLVED] SELECT CASE on Exceptions

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    [RESOLVED] SELECT CASE on Exceptions

    I have an exception object.

    I want to do a select case to perform certain activities in cases when the exception is of a specific type.

    So how would I structure such a SELECT CASE block?

    For instance:
    VB Code:
    1. Select Case ex
    2. Case System.StackOverflowException
    3.  
    4. Case System.ObjectDisposedException
    5.  
    6. End Select
    Obviously, the above doesn't work but you get the idea...
    Last edited by simonm; Jan 19th, 2007 at 04:47 AM.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: SELECT CASE on Exceptions

    Build your try block to catch all the different kind of exceptions.
    VB Code:
    1. Try
    2.  
    3. catch exSO as StackOverflowException
    4. 'overflow occured
    5. catch exOD as ObjectDisposedException
    6. 'etc etc
    7. End Try
    now youll know what exception occured.
    Last edited by Atheist; Jan 18th, 2007 at 07:51 AM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: SELECT CASE on Exceptions

    No, I can't use that method because the exception is passed into another procedure.

    In other words, the place where I am interrogating the exception is not where the exception occurred (nor can that be helped).
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: SELECT CASE on Exceptions

    What you're asking for is not possible because the Select Case syntax doesn't support it. You can do this:
    VB Code:
    1. Select Case True
    2.     Case TypeOf ex Is StackOverflowException
    3.  
    4.     Case TypeOf ex Is ObjectDisposedException
    5.  
    6. End Select
    but that gains you nothing over regular If...ElseIf statements.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: SELECT CASE on Exceptions

    Great thanks. That's just what I want.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width