We help IT Professionals succeed at work.
Get Started

VB.net exception class

Last Modified: 2016-02-11
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)

Open in new window

Partial Class

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

Open in new window

Watch Question
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE