Results 1 to 5 of 5

Thread: Error Handling - call Err.Raise from another module

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    35

    Error Handling - call Err.Raise from another module

    I have the class module and several code modules in ActiveX-dll project. All of modules has common this-module-level procedures as local err handlers. And all of this handlers in different modules are very similar, so I want to move them in special module, containing all err-related procedures.

    But the only question is there for me:

    • Is it correct to raise user-defined err from another module?


    This is especially important in case of the class, that will be many times instanced in user app and I'm afraid this a little bit.

    Say, err conditions are become in My_Class.BadProcedure() and it calls user-err-maintance procedure in Module_Err.ErrRaise() that (after many err attributes assignments) calls finally Err.Raise, that must return us upside on the calls stack to My_Class.BadProcedure() error handler (or err handler on up level).
    .

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Tom!
    No answer. (C)


    Addendum:

    Ok, let's simplify the task.

    Let's forget about the class. It's realy difficult - every time create object by pointer and then destroy it. Let him to use their own copypaste of common error handling code.

    But what about remaining task - to do it between code modules only?
    It is possible, yeh, but is it safe amd correct?

    Code:
    ' Module3
    Public Sub sp_TestErr_Raise(pNmb&, pSrc$, pDsc$)
        Debug.Print "Module3: Beg_sb_TestErr_Raise"
        Call Err.Raise(pNmb + vbObjectError, pSrc, pDsc)
        
        Debug.Print "Module3: End_sb_TestErr_Raise - Never will be printed"
        Stop    ' We can't be here
    End Sub
    
    
    ' Module4
    Private Sub sb_TestErr()
    On Error GoTo ErH
            
        Debug.Print "Module4: Beg_sb_TestErr"
        Call Module3.sp_TestErr_Raise(12345, "Beg_sb_TestErr", "12345")
        
        Debug.Print "Module4: Mid_sb_TestErr"
        Call Module3.sp_TestErr_Raise(54321, "Mid_sb_TestErr", "54321")
            
        Debug.Print "Module4: End_sb_TestErr"
    
    ErX:
        Stop
        Exit Sub
    ErH:
        Debug.Print "Module4: " & _
                    (Err.Number - vbObjectError) & " - " & _
                    Err.Description & " - " & _
                    Err.Source & vbLf
        Stop
        Resume Next
        Resume
    End Sub
    
    '
    ' Module4: Beg_sb_TestErr
    ' Module3: Beg_sb_TestErr_Raise
    ' Module4: 12345 - 12345 - Beg_sb_TestErr
    '
    ' Module4: Mid_sb_TestErr
    ' Module3: Beg_sb_TestErr_Raise
    ' Module4: 54321 - 54321 - Mid_sb_TestErr
    '
    ' Module4: End_sb_TestErr
    '
    .
    Last edited by asbo; Aug 1st, 2018 at 09:38 AM. Reason: Soften task conditions

Tags for this Thread

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