Results 1 to 12 of 12
  1. #1
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    And with the "try catch" in .NET, it is finally possible to apply an error handler which can be used in all routines without having to modify forhard-coded routine names.

    But they still missed out (I think) in being able to apply a single error handler over, say, an entire form, without having to code indiviually into each sub or function (I used to be able to do this im mainframe- what happened in the name of progress?). This would be overridable of course.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    >> apply an error handler which can be used in all routines without having to modify forhard-coded routine names.

    Geoff,

    Could you 'splain that for me? Ah ain't clear on yur meanin'
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    In VB6, I put in an error handler for every module. I have to change that error handler for each module to include the module name. Neither VB6 nor VBA can give me the module name without having to hardcode something.

    (eg:
    <pre>Sub ShowExample()
    On Error GoTo ErrorHandler
    ...
    Exit Sub

    ErrorHandler:
    Msgbox "Err " & Err.Number & " occurred in routine ShowExample"
    </pre>

    But in .NET I don't have to hardcode "ShowExample"- I can determine the routine name programatically (I don't have .NET here, I can't rememeber just how off the top of my head)
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    Gee wiz. That's great. Mr. Liberty never mentioned that in the CBT I've just
    finished. Remeber the posts a while back where I tried to figure out a
    way to get that mod name. This is the best I could do. It's pretty lame,
    but if the actual error message is unique, it works.

    Function GetSubName(ByVal UniqueStr As String, ByVal strMod As String) As String
    Dim Line As Long
    Dim oMod As Object
    Line = 1
    Set oMod = VBE.ActiveVBProject.VBComponents(strMod).CodeModul e
    With oMod
    If .Find(UniqueStr, Line, 1, .CountOfLines, 1) Then
    GetSubName = .ProcOfLine(Line, 0) ' 0 = vbext_pk_Proc
    End If
    End With
    Set oMod = Nothing
    End Function
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    I remember that. From memory though, it did not work in compiled VB.

    I've looked up a manual. I think the info is in the System.Exception class- Source property (and even the StackTrace property)- http://support.microsoft.com/default.aspx?...-us;301283&

    I wonder if it's possible to wrap a "try catch" around all the code in a module to save having to code modules individually
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    Looks like the Source property only gives the project or application name. I'd like to know
    what class raised the exception, the procedure name, the line number and maybe the user's shoe size as well.

    I guess you can parse all that (except the shoe size) from the StackTrace, but that ain't pretty.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    It looks as if the StackTrace can be fairly easy to use- see http://msdn.microsoft.com/msdnnews/2001/ma...m/Classroom.asp.

    I can't try it for a while though.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Error Handling (Word 97 SR2)

    <P ID="edit" class=small>(Edited by gwhitfield on 04-Jan-03 09:54. Moved from the VB/VBA board)</P>I've never used it myself. I'll probably never use it now that I have

    try
    catch
    finally

    finally!!
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    Careful, the namespace for the StackTrace class in C# is

    System.Diagnostics

    not System.Reflection


    weird that they'd be different. Oh well.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Word Error Handling (Word 97 SR2)

    You can set an error handler for an entire form in .NET like this.

    Sub ShowMyForm()
    dim myForm as New whateverYourFormNameIs

    Try
    myForm.Show or ShowDialog
    Catch
    your error handlingcode
    End Try

    This should, according to the documentation, work just fine.

    Regards,

    Kevin Bell

  11. #11
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Word Error Handling (Word 97 SR2)

    In fact, using the Sub Main() method of initiating a program in .NET, you can set a single error handler for the whole program.

    Sub Main()
    Dim myForm as New StartingFormName

    Try
    MyForm.Show
    Catch
    Do the code for the error handling
    Finally
    Whatever yoy want here
    End Try

    I haven't used this in anger but does work.

    Regards,

    Kevin Bell

  12. #12
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Error Handling (Word 97 SR2)

    Thanks Kevin.

    I've found another way to do the same:

    <pre>Private Sub Form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    AddHandler Application.ThreadException, _
    New ThreadExceptionEventHandler(AddressOf Me.CatchAllExceptions)
    End Sub
    '
    Public Sub CatchAllExceptions(ByVal Sender As Object, _
    ByVal Excep As ThreadExceptionEventArgs)
    MsgBox("Unhandled Exception:" & Excep.Exception.Message)
    End Sub
    '
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    Dim BlowMeUp As Integer
    BlowMeUp = "a"
    End Sub</pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Posting Permissions

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