473,320 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

Jan 31 '08 #1
1 1387
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("multiple");

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

Jan 31 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kerri | last post by:
Hi, I am new to .NET In my Error Logic on my Aspx pages when an error happens it hits my catch statement where I throw an Exception. My question is : what is the difference between Thwo...
4
by: Eric Lilja | last post by:
Hello, in my program I have a function (pseudo code): void start_mysql_service() { obtain handle start mysql service using handle if start fails close handle and throw an exception...
3
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
0
by: Lasse Vågsæther Karlsen | last post by:
From the book by Jeffrey Richter: throw; will not change the origin of the exception, whereas throw ex; will change the origin of the exception to this statement. When I try the following...
17
by: hplloyd | last post by:
Hi, I have a function that adds data to a database and I want to return true if the database was updated and false if there was a problem, so I am using a try... catch block... My problem is...
6
by: Arjen | last post by:
Hi, I'm reading the enterprise library documentation and there I see the throw statement. try { // run code } catch(Exception ex) {
6
by: Henryk | last post by:
I did a lot of delphi GUI programming recently. In my experience most of the time you just want to throw a standard exception with a descriptive message. Then all calling functions can handle...
6
by: Fir5tSight | last post by:
Hi, What does "throw" do? I understand that it throws an error when certain exceptional situation happens. My guess is that this *ignores* the error and *continues* so that it prevents the...
28
by: Jess | last post by:
Hello, It is said that if I implement a "swap" member function, then it should never throw any exception. However, if I implement "swap" non- member function, then the restriction doesn't...
6
by: jason.cipriani | last post by:
Consider this program, which defines a template class who's template parameter is the type of an exception that can be thrown by members of the class: === BEGIN EXAMPLE === #include...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.