Err.Raise() is ignoring custom description and source

前端 未结 1 1140
礼貌的吻别
礼貌的吻别 2021-01-12 14:13

I have a class module with a Let function that raises a custom error an example is shown below

Private pValue As Double
Public Property Let Value(v As Double         


        
相关标签:
1条回答
  • 2021-01-12 14:42

    I had the same problem. I figured out that the behaviour changed when the instance of the error raising class was typed explicitly. So if you change the type of your class to variant you should keep your custom error message:

    Sub TestSub()
      Dim Example As Variant   'use Variant instead of Test to keep your custom error message
      Set Example = New Test
    
      On Error GoTo errorHandler
      Example.Value = -1
      On Error GoTo 0
      Exit Sub
    
    errorHandler:
      MsgBox Err.Number & "," & Err.Description & " in " & Err.Source
    End Sub
    
    0 讨论(0)
提交回复
热议问题