Avatar of RCMiller1981
RCMiller1981

asked on 

VB.net exception class

I am trying to use the exception class as coded below to create a new exception with a specific error number, I thought reading the descriptor of HRESULT that I would be able to set the value using a '=', however it throws an error when I do this.  My next step was to implement a partial class that overloads the property for HRESULT, however I obviously either did that wrong, or am trying to use the partial class in a way that it is not meant to.  So, How can I Set a custom Exception, with a custom error number in VB.net?

Dim ex As New Exception("Error message!")
ex.HResult = Int(10001981)
errors()

Open in new window


Partial Class

Partial Class exception
    Inherits System.Exception
    Dim hresult_holder
    Public Overloads Property HRESULT As Integer
        Get
            Return hresult_holder
        End Get
        Set(value As Integer)
            hresult_holder = value
        End Set
    End Property
End Class

Open in new window

Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
RCMiller1981

8/22/2022 - Mon