Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / June 2006

Tip: Looking for answers? Try searching our database.

Try/catch exception using Combobox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pmetz - 20 Apr 2006 01:43 GMT
I'm attempting exception handling for a combobox.  I wish an exception
to be raised if the user does not select an item from the combobox, but
I'm not sure of the correct code.  Here is what I have now:

try
{
   if (cboDwellingType.get_SelectedItem().ToString == null);
   {
     MessageBox.Show("Please select the Dwelling Type from the
dropdown menu.");
     cboDwellingType.Focus();
     throw new Exception ("Error updating Local database");
   }
}
catch
{
   if (err.getMessage() == "Error updating Local database.")
   MessageBox.Show(err.getMessage());
}
pmetz - 20 Apr 2006 01:46 GMT
SORRY...FORGOT THE PARAMETER IN THE CATCH...HERE'S THE UPDATED CODE

try
{
   if (cboDwellingType.get_SelectedItem().ToString == null);
   {
     MessageBox.Show("Please select the Dwelling Type from the
dropdown menu.");
     cboDwellingType.Focus();
     throw new Exception ("Error updating Local database");
   }
}
catch (Exception err)
{
   if (err.getMessage() == "Error updating Local database.")
   MessageBox.Show(err.getMessage());
}
chrismo - 24 Apr 2006 02:37 GMT
Your code looks okay (except it's probably not get_SelectedItem -
rather getSelectedItem) ... but there's no point in throwing an
exception just to catch it and then display the message -- unless
there's a lot more code inside the try before the catch.

Are you having a specific problem with it?
Lars-Inge Tønnessen (VJ# MVP) - 04 Jun 2006 16:52 GMT
Your "throw new Exception ("Error updating Local database");" could be
better implemented. Exceptions should only be thrown when there are
something very vrong you can not handle with your code. Your code should not
throw an exception when the database cannot be updated.

Best Regards,
Lars-Inge Tønnessen
VJ# MVP

> try
> {
[quoted text clipped - 11 lines]
>    MessageBox.Show(err.getMessage());
> }
George Birbilis - 14 Jun 2006 11:42 GMT
> I'm attempting exception handling for a combobox.  I wish an exception
> to be raised if the user does not select an item from the combobox, but
> I'm not sure of the correct code...

Use validator controls instead to "force" the user to select something at
the combobox. There are some from MS (for both WinForms and WebForms) and
some from third parties too (for example see metabuilders.com for some cool
ASP.net ones)

---------------
George Birbilis <birbilis@kagi.com>
Microsoft MVP J# 2004-2006
Borland Spirit of Delphi
http://www.kagi.com/birbilis

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.