Throw Exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Throw Exception

    Hello,

    I have a function named Find as follows:

    Public Function Find() As Control
    Dim AllControls As Control() = FindAll()
    End Function

    FindAll returns can return an array of controls or single control.

    What I want is to create and exception that I would throw as follows:

    If AllControls has more than 1 control then throw the expection:
    "Multiple controls found"

    If AllControls has only 1 control but its type is different from
    TextBox the throw the exception:
    "The control found is not a TextBox"

    If AllControls has only 1 control and is a TextBox then:
    Throw now exception and Return AllControls(0)

    How can I do this?

    Thanks,
    Miguel

  • =?Utf-8?B?TWlzYmFoIEFyZWZpbg==?=

    #2
    RE: Throw Exception

    please pardon my code smaple below i am not very familiar with VB.NET (sample
    code in C#)

    if(AllControls. Length 1)
    throw new Exception("mult iple");

    if(AllControls. Length == 1 && !(AllControls[0] is TextBox))
    throw new Exception("not textbox");

    return AllControls[0];



    --
    Misbah Arefin



    "shapper" wrote:
    Hello,
    >
    I have a function named Find as follows:
    >
    Public Function Find() As Control
    Dim AllControls As Control() = FindAll()
    End Function
    >
    FindAll returns can return an array of controls or single control.
    >
    What I want is to create and exception that I would throw as follows:
    >
    If AllControls has more than 1 control then throw the expection:
    "Multiple controls found"
    >
    If AllControls has only 1 control but its type is different from
    TextBox the throw the exception:
    "The control found is not a TextBox"
    >
    If AllControls has only 1 control and is a TextBox then:
    Throw now exception and Return AllControls(0)
    >
    How can I do this?
    >
    Thanks,
    Miguel
    >
    >

    Comment

    Working...