Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

How to throw an exception in a class library

I have 2 functions in a class library performing various things. I will make use of this dll in a form by instantiating it and calling the functions. How can I introduce a try catch block in my functions to throw any error that occurs if an error is encountered. I know you throw exceptions in dll's but not sure if I have to use the new keyword.


public function GetLastName(byval lastname as string)

--- body of the code

catch (ex as exception)

End function

Then, How will I handle this in my form calling this function.


1 Solution
            'code body
        Catch ex As Exception
            Throw New Exception(ex.Message)
            Exit Function
        End Try

in the code you will have this to access your method (assume this method is located in class ClassName in the library)

Dim c As New ClassName
Dim lastName as string
    Label1.Text = c.GetLastName(lastName)
Catch ex As Exception
    'Error handling
End Try

if an error occurs in your library it should toss the error up until you catch it and deal with it or the error comes out outside a try catch.  I hope this helps.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now