none
VB.NET Error: "Catch cannot catch type 'Object' because it is not 'System.Exception'"

    Question

  • Hello, I'm having some trouble in VB.NET framework 4.5. I've built an automatic field entry tied to a browser and everything works fine except my last instruction:

     Catch obj1 As Object
                Me.take1(&HFA0)

    "take1" is a private sub to navigate to a link in the browser and start a timer. I have no idea how to fix this. Could anyone assist me?

    Friday, August 30, 2013 7:36 PM

Answers

  • If you are creating your own custom exception object, just make sure the class "Inherits system.exception"

    That would only be applicable if he were creating his own Exception class:

    Public Class MetaDataMissingException Inherits Exception Public Sub New() End Sub Public Sub New(ByVal message As String) MyBase.New(message) End Sub Public Sub New(ByVal message As String, ByVal inner As Exception) MyBase.New(message, inner) End Sub End Class


    But he's not. It's declared as type Object.


    Please call me Frank :)

    Friday, August 30, 2013 9:34 PM

All replies

  • Why are you declaring obj1 as a type Object rather than a type Exception?

    Please call me Frank :)

    Friday, August 30, 2013 8:18 PM
  • Hello,

    Inline with Frank's question, you really should read about Try/Catch statement documentation.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Friday, August 30, 2013 8:27 PM
  • Anytime that I get into a discussion about Exception Handling, I bring up this three minute video which I copied to my site.

    It's a bit esoteric, but it's worth three minutes. ;-)


    Please call me Frank :)

    Friday, August 30, 2013 8:36 PM
  • If you are creating your own custom exception object, just make sure the class "Inherits system.exception"

    “If you want something you've never had, you need to do something you've never done.”

    Don't forget to mark helpful posts and answers ! Answer an interesting question? Write a new article about it! My Articles
    *This post does not reflect the opinion of Microsoft, or its employees.

    Friday, August 30, 2013 9:28 PM
    Moderator
  • If you are creating your own custom exception object, just make sure the class "Inherits system.exception"

    That would only be applicable if he were creating his own Exception class:

    Public Class MetaDataMissingException Inherits Exception Public Sub New() End Sub Public Sub New(ByVal message As String) MyBase.New(message) End Sub Public Sub New(ByVal message As String, ByVal inner As Exception) MyBase.New(message, inner) End Sub End Class


    But he's not. It's declared as type Object.


    Please call me Frank :)

    Friday, August 30, 2013 9:34 PM
  • If you are creating your own custom exception object, just make sure the class "Inherits system.exception"

    That would only be applicable if he were creating his own Exception class:

    Public Class MetaDataMissingException Inherits Exception Public Sub New() End Sub Public Sub New(ByVal message As String) MyBase.New(message) End Sub Public Sub New(ByVal message As String, ByVal inner As Exception) MyBase.New(message, inner) End Sub End Class


    But he's not. It's declared as type Object.


    Please call me Frank :)


    thats why I said if

    “If you want something you've never had, you need to do something you've never done.”

    Don't forget to mark helpful posts and answers ! Answer an interesting question? Write a new article about it! My Articles
    *This post does not reflect the opinion of Microsoft, or its employees.

    Friday, August 30, 2013 10:16 PM
    Moderator
  • thats why I said if

    :)

    Ya know, I was just thinking -- we're all assuming that he's got a Try/Catch set up and what he posted was an excerpt, but I guess we don't really know that.

    I'm interested in his response.


    Please call me Frank :)

    Saturday, August 31, 2013 12:18 AM