473,467 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

exception issues

I have an exception that is being caught and handled correctly in my VS IDE. However the compiled version throws an unhandled exception when it reaches that point...here is some code....

this is where the unhandled is being raised:

Try
........

Dim prodcol As New Mountaire.Database.Products.ProductsCollection(mLo cation)
prodcol.Add(mNewProduct)
Catch ex As Mountaire.Database.Products.ProductExistsException
Me.Hide()
Me.DialogResult = DialogResult.Cancel
Throw New Mountaire.Database.Products.ProductExistsException
Catch ex As InvalidCastException
MessageBox.Show("You must fill in Pluno and Product Code.", "Invalid Input")
Me.DialogResult = DialogResult.Abort

Finally

End Try
however in the calling code this is what I have:
try
......
dlgResult = frm.ShowDialog

If dlgResult = DialogResult.OK Then
Me.fillProductInformation(mLocation)
index = CInt(frm.txtPluno.Text)
'debug.WriteLine(frm.NewProduct.PluNo)
Else
Throw New Mountaire.GenericException.ActionCanceledException
End If
Loop Until dlgResult <> DialogResult.Abort

Catch ex As Mountaire.GenericException.ActionCanceledException
index = 0
Catch ex As Products.ProductExistsException
MessageBox.Show(ex.Message, "Product Already Exists")
index = CInt(frm.txtPluno.Text)
Catch ex As Exception
MessageBox.Show(ex.ToString, "Exception Thrown")
Finally
Me.mProductCM.Position = mProductCollection.IndexOf(index)

End Try
Any Ideas?
--
--Eric Cathell, MCSA
Nov 23 '05 #1
3 1139
A couple of things

1) What is the unhandled exception? What does it say? Perhaps it is the CInt call in the catch block throwing the exception
2) It looks like you are using exceptions as a signal of a business error. This is generall not recommended. Throwing errors is meant for critical application problems. For logical errors, you should be returning a code to indicate this, and then dealing with the problem accordingly. Additionally, throwing exceptions to indicate logic errors all over the place is going to hurt performance.
"ECathell" <ec******@nospam.com> wrote in message news:%2******************@TK2MSFTNGP12.phx.gbl...
I have an exception that is being caught and handled correctly in my VS IDE. However the compiled version throws an unhandled exception when it reaches that point...here is some code....

this is where the unhandled is being raised:

Try
.......

Dim prodcol As New Mountaire.Database.Products.ProductsCollection(mLo cation)
prodcol.Add(mNewProduct)
Catch ex As Mountaire.Database.Products.ProductExistsException
Me.Hide()
Me.DialogResult = DialogResult.Cancel
Throw New Mountaire.Database.Products.ProductExistsException
Catch ex As InvalidCastException
MessageBox.Show("You must fill in Pluno and Product Code.", "Invalid Input")
Me.DialogResult = DialogResult.Abort

Finally

End Try
however in the calling code this is what I have:
try
.....
dlgResult = frm.ShowDialog

If dlgResult = DialogResult.OK Then
Me.fillProductInformation(mLocation)
index = CInt(frm.txtPluno.Text)
'debug.WriteLine(frm.NewProduct.PluNo)
Else
Throw New Mountaire.GenericException.ActionCanceledException
End If
Loop Until dlgResult <> DialogResult.Abort

Catch ex As Mountaire.GenericException.ActionCanceledException
index = 0
Catch ex As Products.ProductExistsException
MessageBox.Show(ex.Message, "Product Already Exists")
index = CInt(frm.txtPluno.Text)
Catch ex As Exception
MessageBox.Show(ex.ToString, "Exception Thrown")
Finally
Me.mProductCM.Position = mProductCollection.IndexOf(index)

End Try
Any Ideas?
--
--Eric Cathell, MCSA
Nov 23 '05 #2
thanks for the tips...I attached to the process and its breaking on the exception that would return control to the calling form.

the unhandled exception is the message of my ProductExistsException...

Mountaire.Database.Products.ProductExistsException : This Product Already Exists
at Mountaire.Database.Products.ProductsCollectionBase .Add(Product obj)
at frmAddNewProduct.btnOK_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I will rethink my exception strategies...I may have misinterpreted some article I read before I started doing this. Maybe I should be using events instead of exceptions...anyway the article was about different strategies to terminate loops and handle error conditions in applications...
--
--Eric Cathell, MCSA
"Marina" <so*****@nospam.com> wrote in message news:up**************@TK2MSFTNGP10.phx.gbl...
A couple of things

1) What is the unhandled exception? What does it say? Perhaps it is the CInt call in the catch block throwing the exception
2) It looks like you are using exceptions as a signal of a business error. This is generall not recommended. Throwing errors is meant for critical application problems. For logical errors, you should be returning a code to indicate this, and then dealing with the problem accordingly. Additionally, throwing exceptions to indicate logic errors all over the place is going to hurt performance.
"ECathell" <ec******@nospam.com> wrote in message news:%2******************@TK2MSFTNGP12.phx.gbl...
I have an exception that is being caught and handled correctly in my VS IDE. However the compiled version throws an unhandled exception when it reaches that point...here is some code....

this is where the unhandled is being raised:

Try
.......

Dim prodcol As New Mountaire.Database.Products.ProductsCollection(mLo cation)
prodcol.Add(mNewProduct)
Catch ex As Mountaire.Database.Products.ProductExistsException
Me.Hide()
Me.DialogResult = DialogResult.Cancel
Throw New Mountaire.Database.Products.ProductExistsException
Catch ex As InvalidCastException
MessageBox.Show("You must fill in Pluno and Product Code.", "Invalid Input")
Me.DialogResult = DialogResult.Abort

Finally

End Try
however in the calling code this is what I have:
try
.....
dlgResult = frm.ShowDialog

If dlgResult = DialogResult.OK Then
Me.fillProductInformation(mLocation)
index = CInt(frm.txtPluno.Text)
'debug.WriteLine(frm.NewProduct.PluNo)
Else
Throw New Mountaire.GenericException.ActionCanceledException
End If
Loop Until dlgResult <> DialogResult.Abort

Catch ex As Mountaire.GenericException.ActionCanceledException
index = 0
Catch ex As Products.ProductExistsException
MessageBox.Show(ex.Message, "Product Already Exists")
index = CInt(frm.txtPluno.Text)
Catch ex As Exception
MessageBox.Show(ex.ToString, "Exception Thrown")
Finally
Me.mProductCM.Position = mProductCollection.IndexOf(index)

End Try
Any Ideas?
--
--Eric Cathell, MCSA
Nov 23 '05 #3
What I would do in this case, is first see if the product is in the collection. If it is, I would return the appropriate code to the calling form, so it could handle this case appropriately. If the product is not, then it is safe to add it.

I am not sure if events are appropriate here, at least from what you have described.
"ECathell" <ec******@nospam.com> wrote in message news:eB**************@tk2msftngp13.phx.gbl...
thanks for the tips...I attached to the process and its breaking on the exception that would return control to the calling form.

the unhandled exception is the message of my ProductExistsException...

Mountaire.Database.Products.ProductExistsException : This Product Already Exists
at Mountaire.Database.Products.ProductsCollectionBase .Add(Product obj)
at frmAddNewProduct.btnOK_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I will rethink my exception strategies...I may have misinterpreted some article I read before I started doing this. Maybe I should be using events instead of exceptions...anyway the article was about different strategies to terminate loops and handle error conditions in applications...
--
--Eric Cathell, MCSA
"Marina" <so*****@nospam.com> wrote in message news:up**************@TK2MSFTNGP10.phx.gbl...
A couple of things

1) What is the unhandled exception? What does it say? Perhaps it is the CInt call in the catch block throwing the exception
2) It looks like you are using exceptions as a signal of a business error. This is generall not recommended. Throwing errors is meant for critical application problems. For logical errors, you should be returning a code to indicate this, and then dealing with the problem accordingly. Additionally, throwing exceptions to indicate logic errors all over the place is going to hurt performance.
"ECathell" <ec******@nospam.com> wrote in message news:%2******************@TK2MSFTNGP12.phx.gbl...
I have an exception that is being caught and handled correctly in my VS IDE. However the compiled version throws an unhandled exception when it reaches that point...here is some code....

this is where the unhandled is being raised:

Try
.......

Dim prodcol As New Mountaire.Database.Products.ProductsCollection(mLo cation)
prodcol.Add(mNewProduct)
Catch ex As Mountaire.Database.Products.ProductExistsException
Me.Hide()
Me.DialogResult = DialogResult.Cancel
Throw New Mountaire.Database.Products.ProductExistsException
Catch ex As InvalidCastException
MessageBox.Show("You must fill in Pluno and Product Code.", "Invalid Input")
Me.DialogResult = DialogResult.Abort

Finally

End Try
however in the calling code this is what I have:
try
.....
dlgResult = frm.ShowDialog

If dlgResult = DialogResult.OK Then
Me.fillProductInformation(mLocation)
index = CInt(frm.txtPluno.Text)
'debug.WriteLine(frm.NewProduct.PluNo)
Else
Throw New Mountaire.GenericException.ActionCanceledException
End If
Loop Until dlgResult <> DialogResult.Abort

Catch ex As Mountaire.GenericException.ActionCanceledException
index = 0
Catch ex As Products.ProductExistsException
MessageBox.Show(ex.Message, "Product Already Exists")
index = CInt(frm.txtPluno.Text)
Catch ex As Exception
MessageBox.Show(ex.ToString, "Exception Thrown")
Finally
Me.mProductCM.Position = mProductCollection.IndexOf(index)

End Try
Any Ideas?
--
--Eric Cathell, MCSA
Nov 23 '05 #4

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

Similar topics

17
by: Bryan Bullard | last post by:
hi, is there a way to force the user of an object to catch exceptions of specific type? for instance a compile error is issued if exception 'ExeceptionXXX' thrown by method...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
15
by: Mark Lewis | last post by:
I have a weird error trapping problem. When running the IDE everything works fine but not when running in an EXE I get the Unhandled Exception Error message box intead of the one in my Try....Catch...
3
by: c676228 | last post by:
Hi everyone, I have a piece of code in sales.aspx.vb like this: Protected WithEvents Message As System.Web.UI.WebControls.Label Try ... ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr +...
5
by: David Thielen | last post by:
Hi; I have added the code to my code behinds of: private void Page_Error(object sender, EventArgs e) { throw Server.GetLastError(); } But I now have the problem that the call stack I get is...
11
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example,...
4
by: Arnie | last post by:
Folks, The GZipStream class in .NET is throwing an exception during an OS unseal/power up (first boot experience). The .NET system is fully up as other apps seem to run fine.
9
by: AG | last post by:
I occassionally get the following exception from an ASP.NET 2.0 Web Application running on a shared web host. I have no way of knowing what the actual request page was as it never happens when I...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
6
by: Steve | last post by:
Hi All I have a windows forms Application (SAM) in vb.net 2008 using .net framework V2 One and only one customer out of 30 customers is getting errors daily where they have to close and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
1
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.