CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2000
    Location
    AZ
    Posts
    5

    How do I throw an exception in VB?

    I am trying to implement some structured exception handling (VC++ background). How do I throw an exception in VB?

    Thanks in advance
    Erik Johnson

    Erik Johnson

  2. #2
    Join Date
    Feb 2000
    Location
    South Carolina, US
    Posts
    36

    Re: How do I throw an exception in VB?

    They're called events in VB I believe. Declare them at the top of the module that uses them and call them with RaiseEvent.

    Event foo()

    Private Sub Command1_Click()
    RaiseEvent foo
    End Sub

    Though when you think about it, how "structured" *is* the exception system? Return values for success or failure are more structured, exceptions are nothing but GOTOs.


  3. #3
    Join Date
    Feb 2000
    Location
    AZ
    Posts
    5

    Re: How do I throw an exception in VB?

    Hmm... In VC++ you can throw an exception and pass back a strucure or an error class and have multiple handlers triggered on the type of class being returned. I am guessing that there is no equivelant in VB? Layering function error return types does not sound fun but I guess it's do-able.

    Thanks for your help,
    Erik


    Erik Johnson

  4. #4
    Join Date
    Oct 1999
    Location
    Broomfield, CO
    Posts
    3,382

    Re: How do I throw an exception in VB?

    >> Return values for success or failure are more structured, exceptions are nothing but GOTOs

    Do you mean this in a VB context, because exceptions are certainly more than that in some other languages (C++ and Java: stack is unwound and destructors are called without the programmer having to code anything)?

    I'm not very familiar with VB or its exception handling abilities, so I'm just asking.


  5. #5
    Guest

    Re: How do I throw an exception in VB?

    Weasel: No, I believe you can declare them with variables, but the *concept* of an exception is too haphazardly break from a *general location* exact point unknown to throw execution somewhere else entirely. Give it an arg list and it should work fine. And as opposed to passing structures, there's always that one other hated method of passing large and/or complex things. (But extremely useful) Global vars!


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

Featured