Learn how to a build a cloud-first strategyRegister Now

x
  • 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.

e.g

public function GetLastName(byval lastname as string)

try
--- body of the code

catch (ex as exception)


End function


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

Thanks.


0
Sirdots
Asked:
Sirdots
1 Solution
 
MajinLokiCommented:
       Try
            '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
lastName="Mylastname"
Try
    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.
0

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