473,657 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The Land Of The Lost Exception

I just ran across an interesting phenon...

If you bind a control, say a textbox, to a class.property, and in
changing the value of the textbox an error is thrown in the
class.property, you get stuck in the textbox and cannot leave:

Public Class XClass
Private myName as String
Public Property Name as String
Get
Return myName
End Get
Set (Value as String)
if Value = "Bob" Then
Throw New Exception("Name Cannot Be Bob")
Else
myName = value
End If
End Property

---------------- On the form, you have a textbox (textbox1)
-------------

Private myXClass as New Xclass

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

TextBox1.DataBi ndings.Add New Binding("Text", myXClass, "Name")

End Sub

-------------------------------

So, if you change the textbox from "Mary" to "Bob", the exception seems
to get thrown, but I can't figure out how to catch it.

Any ideas?

--Zorpy
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
4 1144
Zorpy,
Using the Application.Thr eadException event you can trap the exception &
show it to the user or log it. Something like:

Public Shared Sub Main()
AddHandler Application.Thr eadException, AddressOf
Application_Thr eadException
Application.Ena bleVisualStyles ()
Application.DoE vents()
Application.Run (New ZorpiedoMan)
End Sub

Private Shared Sub Application_Thr eadException(By Val sender As Object,
ByVal e As System.Threadin g.ThreadExcepti onEventArgs)
MessageBox.Show (e.Exception.To String(), e.Exception.Mes sage)
End Sub

In the above case I might consider having my validation code throw a
ValidationExcep tion, allowing Application_Thr eadException to decide to show
it to the user or simply log it.

Where ValidationExcep tion is a new class that inherits from System.Exceptio n
with information on what validation failed...

Private Shared Sub Application_Thr eadException(By Val sender As Object,
ByVal e As System.Threadin g.ThreadExcepti onEventArgs)
If TypeOf e.Exception is ValidationExcep tion Then
' handle validation exceptions
Else
' handle unhandled exceptions
End
MessageBox.Show (e.Exception.To String(), e.Exception.Mes sage)
End Sub

Note I normally do my logging in a global exception handler.

Also I use try/finally more then I use try/catch. I only use try/catch when
there is something specific that I need to do with the exception, otherwise
I let my global exception handlers handle the exception.
Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.Http Application.Err or event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomai n.UnhandledExce ption event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows. Forms.Applicati on.ThreadExcept ion event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.Thr eadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.Thr eadException handler will catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay

"ZorpiedoMa n" <No********@Bea tles.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I just ran across an interesting phenon...

If you bind a control, say a textbox, to a class.property, and in
changing the value of the textbox an error is thrown in the
class.property, you get stuck in the textbox and cannot leave:

Public Class XClass
Private myName as String
Public Property Name as String
Get
Return myName
End Get
Set (Value as String)
if Value = "Bob" Then
Throw New Exception("Name Cannot Be Bob")
Else
myName = value
End If
End Property

---------------- On the form, you have a textbox (textbox1)
-------------

Private myXClass as New Xclass

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

TextBox1.DataBi ndings.Add New Binding("Text", myXClass, "Name")

End Sub

-------------------------------

So, if you change the textbox from "Mary" to "Bob", the exception seems
to get thrown, but I can't figure out how to catch it.

Any ideas?

--Zorpy
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2
Jay -

Many, MANY thanks for this thoughful and complete answer. Not only have
you given me a good response to my question, you have given me some new
insights as to error handling in general. I had error handling in VB6
down pat, but had not yet had the time/energy/knowledge to get a
comfortable, standard way of handling errors yet in .NET. This will
help a lot in that endeavor. Thanks again.

--Zorpy

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3
Jay -

I'm only now getting around to trying your suggestions and reading
the article you suggested. (Finally!)

Guess What? Neither your sample, or any of the samples in the
article catch the exception either!

Now What?

--Zorpie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4
Zorpie,
If you are referring to the info I gave over a month ago, you will need to
include more information on what specifically is not working, as the example
and articles I gave work as advertised. Which of course may not be exactly
what you are expecting.

Hope this helps
Jay

"ZorpiedoMa n" <No********@Bea tles.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Jay -

I'm only now getting around to trying your suggestions and reading
the article you suggested. (Finally!)

Guess What? Neither your sample, or any of the samples in the
article catch the exception either!

Now What?

--Zorpie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #5

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

Similar topics

0
1568
by: jackson marshmallow | last post by:
I have just recreated several (large) tables in the database as InnoDB and reloaded them using my client application... These tables used to be MyISAM. I haven't tried playing with any InnoDB parameters, right now everything is default. Some operations a noticeably slower, which can probably be fixed. Speed is not essential right now. But I did run into one strange problem with a batch INSERT SELECT that would take about an hour with...
1
2315
by: Oscar Thornell | last post by:
Hi, I have an ASP.NET page that generates an Exception... The Exception is not caught in the executing method...so it propagates to..the Page_Error event handling method.. In that method the Exception is handled by the client exception policy...basically it logs the information coming from the business layer... We then create a custom message object that contains user/context specific information and adds that to the Session object.....
2
1364
by: Maks Romih | last post by:
I'm not experienced in db2, but I have to write some rather complex processing with stored procedures for db2 on as400. The database consists of some twenty tables and is prepared in advance so it does not change, while I run my procedures. I call the procedures over ODBC from a Microsoft Access and Microsoft Windows client. The procedures also doesn't write anything into this database, but all the output goes into "global temporary...
3
3418
by: Jurgen Appelo | last post by:
I asked this question earlier, but unfortunately the two replies I got did not solve the problem. Here it is again, but now with the code: After an Update my FormView always loses its viewstate values. The field values in the FormView are always overwritten by the results of the Update method in the business layer. No matter what I do, the databind always takes place, even when I don't want it to. See the example below. This is a...
4
2864
by: Sarah Marriott | last post by:
Our website contains session variables that are used to validate if a user is logged in etc. We have found that these variables are randomly lost while navigating the website. We set up some basic code (as shown below) which used a meta tag to refresh an aspx page every second. It tests whether there is any content in a session variable, if not then it writes a timestamp to a text file, recreates the data in the variable and continues....
3
1676
by: AlonR | last post by:
Hi, We're experiencing random user sessions losses on our web applications, and are researching for any useful information which may shed light on this problem. Environment: In our company, we're developing a web product based on ASP.NET 2.0, in conjunction with Oracle database over ADO.NET and external COM objects
1
1465
by: =?Utf-8?B?U00=?= | last post by:
Background We migrated our Asp.net 1.1 application to Asp.net 2.0 ( just migration ) .. It was working fine in local developer machine and one of our development testing server. When we moved to staging server which is also running on windows 2000 server and we started facing a peculiar issue. We are able to login successfully every time , however , a click on a link to move to a a different page on a hyper link. <asp:HyperLink...
13
3053
by: SAL | last post by:
Okay, don't bash me to hard for my design on this app, it's my first web app and it's in production. My basic design is using Datatables created via the designer with a business logic class in between the datatable and ObjectDataSources. In one page I had a Gridview with select enabled. When an row in the grid is selected, I retrieve the SelectedValue, store the value in a Session variable and redirect the response to another web page,...
0
1842
by: Pheasant Plucker® | last post by:
Hi there, Not sure if this is the correct ng and I am not a programmer so excuse me but here goes...:-) We have a custom application that has a hook or calls either the Outlook calendar or looks in the Inbox for a specific email and acts upon it if found. This has worked great for over a year but when I updated using the usual
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.