Event Causing Error - Cannot Catch Exception

Apr 22, 2010

A developer has created a custom control in ASP.NET using VB.NET. The custom control uses a repeater. In certain scenarios, the rpt_ItemDataBound event is encountering a data error. My goal is rather than having the user see the yellow screen of death, give the user a friendlier error explaining exactly what the data error is. I figured I would be able to use a Try/Catch block as shown below throw the exception, however, it appears that the event has nowhere to be thrown to and stops executing at the "End Try" line.

Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rpt1.ItemDataBound, rpt2.ItemDataBound
Try
ProcessBadData...
Catch ex As Exception
Throw ex
End Try
End Sub

In VB.NET, I can find where the repeater's DataSource is being set, however, I can not find a DataBind event. How I can capture the exception in this ASCX control so I can report it to the user. The stack trace looks like this. There is another repeater within the repeater that is actually causing the error (rptOther) and I'm able to catch the error, but I can only throw it to the rpt_ItemDataBound. How rpt_ItemDataBound is getting called without a DataBind event.

at Company.WebForms.Control.rptOther_ItemDataBound(Object sender, RepeaterItemEventArgs e)
at System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e)
at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.Repeater.DataBind()
at Company.WebForms.Control.rpt_ItemDataBound(Object sender, RepeaterItemEventArgs e)

View 1 Replies


ADVERTISEMENT

Error 68 'Catch' Cannot Catch Type 'Microsoft.Office.Interop.Outlook.Exception' Because It Is Not 'System.Exception'

Feb 12, 2010

I am using VB.NET 2005 to create a Windows forms application. I have a procedure named SendMail that creates an instance of Outlook.Application, to send an email from my application. I found the code on this forum, I think.The procedure works fine, but I can't use error handling with it.I call the procedure from a button click event. I put the procedure call in a try/catch block, and the application won't build, with the following error.

Error 68 'Catch' cannot catch type 'Microsoft.Office.Interop.Outlook.Exception' because it is not 'System.Exception' or a class that inherits from 'System.Exception'. C:datadevdmtiQTSQTSv7_1_20100212wQTSQTSReportsCriteria
pt_frmReportViewer.vb 43 21 QTS

Here is the code:

Sub SendMail(ByVal sFile As String)
' Create an Outlook application.
Dim oApp As Outlook._Application

[code]....

View 8 Replies

Error - Catch Cannot Catch Type 'Microsoft.Office.Interop.Outlook.Exception'

Mar 25, 2011

I have a program in VB.Net that receives mails from Outlook, extracts attachments and inserts the attachments into a table through a query. I would like to put the query/queries in a Try/Catch block, but cannot do so as Outlook exceptions cannot be caught, and it gives me an error, and unless I put a very specific exception, I cannot catch it. Is there a workaround?

Edit:

Try
Catch ex As Exception
End Try

Exception is underlined and when I hover on it, it says: "Catch cannot catch type 'Microsoft.Office.Interop.Outlook.Exception' because it is not in 'System.Exception' or a class that inherits from 'System.Exception'". This is affecting all my other code which I'd like to put into a Try/Catch block.

View 2 Replies

Button_click Event Will Not Stop Execute After Error Catch Using Try - Catch Statement

Apr 1, 2011

i have problem when i click a ADD button, there is one null value in the textbox .. so the try catch statemnt is to catch that null value error but after that the catch is success but the button click never stop excute the statemnt till the end of the button event.

View 6 Replies

Catch An Exception Thrown By A Control Event?

Jan 21, 2011

How can I catch an exception thrown by a control event?I have a control that throws an exception in one of its events and I need to catch it but I don't know how.Consider for example that the text box control throws an exception in its click event. How can I catch such exception?

View 3 Replies

Catch As Exception Error From Lblfeedback

May 11, 2012

i must receive that block of an error message from lblfeedback when it happens so i can sort out the problem before the phone rings. i have this block of code

[Code]....

View 2 Replies

Catch 404 Error Exception On Web Browser Control

May 28, 2011

How can I catch 404 error on web browser control?

Try
TimeTable.Navigate("URL/File.htm")
Catch ex As Exception
TimeTable.Navigate("URL/File2.html")
End Try

View 1 Replies

Catch' Cannot Catch Type 'Object' Because It Is Not 'System.Exception' Or A Class That Inherits From 'System.Exception'

Aug 10, 2010

I'm getting 'Catch' cannot catch type 'Object' because it is not 'System.Exception' or a class that inherits from 'System.Exception'. and 'Expression detected' Code underlined in blue: Catch obj1 As Object When (?)

Private Sub OpenJAMem()
Dim num3 As Integer
Try

[code]....

View 2 Replies

Catch Ex As Exception Error - CDate Function Is Null

Jun 24, 2011

In the following code an error arises because the date being passed to the cDate function is Null. However, the catch statement is in error and reports index out of range on the Catch Ex as Exception line. The exception helper says the word Exception is in error and advises that it is index out of range.

View 12 Replies

'Catch' Cannot Catch Type 'exception' Because It Is Not 'System.Exception'?

Apr 16, 2012

I have a project converted from Visual Studio 2005 to Visual Studio 2010. It compiles and runs.

When I prune "unused references's from this project as listed by Visual Studio, the project fails to compile with the subject error message.

In particular one of the "unused refererences" is to "Microsoft.VisualBasic.dll". The IDE does not allow me to add back this particular reference.

What do I need to add back as a referenceto get this items?

View 4 Replies

Nested Try...Catches - If An Exception Occurs In The 2nd Sub's Try...Catch, Which Catch Gets Excecuted?

Mar 4, 2009

I have this scenario: in a Sub I have a Try...Catch statement.Within that Try..Catch I call another sub.In that 2nd sub is also a Try...Catch.(see below for example).Now if an exception occurs in the 2nd sub's Try...Catch, which Catch gets excecuted? The 2nd one, the 1st one or both?

Private Sub sub1()
Try
..do stuff[code].....

View 3 Replies

If Throw An Exception From Within A Catch, Does The Finally (from The Catch) Still Execute

Jun 2, 2009

If I throw an exception from within a catch, does the finally (from the catch) still execute? i.e.

Try
..some code with an exception in it...
catch ex as Exception
throw new SpecialException("blah blah" & ex.Message, ex)

[code]....

View 6 Replies

Catch An Exception And Throw A New Exception Which Wraps The First Exception As An Inner Exception

May 8, 2009

It is possible to catch an exception and throw a new exception which wraps the first exception as an inner exception: [URL] Also, if I call a function and it throws a certain error, but I catch it, will the calling code's catch handler execute? If so, and it is of a higher exception type, is this not wrapping the exception? eg I can throw exception ex of type IndexOutOfRange, log it but rethrow, catch a higher up exception and do something, or I can throw a new exception and wrap an inner exception like:

View 1 Replies

Restructure Try / Catch To Eliminate Error On Myreader.close Command In Catch Part?

Jun 19, 2012

The following code causes a "Warning" that Variable is used before value assigned.How do I restructure this Try/catch to eliminate error on the myreader.close command in the Catch part? Code appears to work fine but I dont like Warnings. [code]

View 8 Replies

WPF User Control Is Causing Out Of Memory Exception?

Mar 8, 2010

I have created a windows form based application and I want the form to add a user specified amount of user controls (with textboxes) on to a panel. The user can then click some button and the controls on this panel are cleared and new ones are added. The user does something and the process is repeated. Now, I wanted these textboxes to support spell checking and looked all over for a free solution.

WPF textboxes support spell checking where the ones in regular win forms do not. I thought I would be able to use these WPF textboxes by adding them to an ElementHost object which is, in turn, within a panel. This panel would be a user control.

So, in my application, I would be able to add instances of these user controls onto the form and make use of .NET's spell checking goodness. This actually worked but after using the application for a while, found that the application would eventually freeze on me due to out of memory errors. I have pinpointed the memory errors to these WPF controls since this problem does not happen with normal textboxes.

When the window is opened and the number of controls is specified, this is pretty much how the controls are added:

Dim xOffset As Integer = 0
For i As Integer = 0 To theNumber
Dim myUserControl As New SpecialUserControl()

[Code].....

There are a lot of results on the internet when I tried to find a solution and I'm thinking that the problem I am having is due to the fact that the WPF control is not going away even after clearing the panel. Following this conclusion, I have tried different solutions regarding disposing these controls or setting them to nothing but the memory problem keeps occurring.

View 1 Replies

.net - Re-throwing An Exception From An Exception Catch?

Feb 14, 2011

catch an exception and then throw another exception? Like so:

Try
' Do operation xxx
Catch ex As Exception
' Operation xxx failed, need to execute cleanup

[code]....

The reason for doing this is that while I catch my exception on a higher level logic (to make sure I can log it properly), I need to do some actions in the event of the exception that I can only do inside my class/function.

View 3 Replies

VS 2008 Errorhandleing Routine Causing First Chance Exception?

Sep 23, 2009

For the life of me i can't figure out why this is throwing a first chance exception error. The error I'm getting in the immediate window is

Quote:
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll

[code].....

View 7 Replies

Make The Custom Exception Thrown In BackGroundWorker DoWork Event The Error In RunWorkerCompletedEventArgs?

Oct 6, 2010

Let's say a custom exception is thrown in the DoWork event for a backgroundworker. How do I pass the custom exception to the backgroundworker so that it ends up being the e.Error in the RunWorkedCompletedEventArgs?

View 1 Replies

Catch Inner Exception In NET?

Oct 13, 2009

How can I catch an inner exception in .NET? I need to check 2 databases for a record. The database code throws an exception if a record is not found, so then I want to check the second database[code]...

View 5 Replies

How To Catch Exception From DLL

Sep 8, 2011

I've written a DLL that contains a bunch of classes. One of my methods validates the contents of a file and throws any necessary exceptions based on invalid content - I'm using a standard "throw new exception." call the thing is, when my code reaches the line where the exception is thrown, my Visual Studio IDE hangs up on that line instead of the external call to my validate method.

[Code]...

So my IDE is actually pulling up the VB file that contains the DLL content and highlights the line in the ValidateFile instead of just hanging on the oFC.ValidateFile method line where the exception is thrown instead of the IDE hanging on the oFC.ValidateFile line in my calling application.

I just want user to have access to the any exceptions that are raised. Here if "C:FileThatDoesntExist.txt" file does not exist then Dll throw exception which should be catch through Application.ThreadException.. How to Catch exception from DLL ?

View 3 Replies

How To Catch This Exception

May 1, 2012

System.Data.OleDbException (0x80004005): The changes you requested to the table were not successful because they would create duplicate values in the index, primary key..."I know how to catch all exceptions. But I want to catch THIS SPECIFIC ONE so I can call one of my subroutines to generate a different ID that will not violate the primary key.

View 2 Replies

VS 2008 - Array - Error Report Shows An Event Type Of Clr203r And An Index Out Of Range Exception

Aug 12, 2011

I have one user that is having a problem with my application, the error report shows an event type of clr203r and an index out of range exception. From what I've read this seems to have "something" to do with arrays or lists. (What that something is, so far, is beyond me or anything I've researched). I do have one array in my program -- myarray(13) as byte and I do have the syntax right as far as noting 20 elements in it. in my other bits of code.

I'm reading those bytes in the serial port, deciphering them and performing some actions. (to be vague). But just with what I've said, can anyone point me to a possible problem? Is the index out of range exception ALWAYS concerned with just arrays or lists? Or could it be something else?

View 16 Replies

.net - Log With Asp.net HealthMonitoring An Exception That Was Catch?

Sep 2, 2011

I configured HealthMonitoring in my web application to log all exceptions in the database.But, when I gracefully handle some exception by showing a nice message to the user, they are not logged in the database.If I something like Throw ex, the standard error page is be displayed and the error is not gracefully handled.

Is there something else I could add at the end of my error handler to tell the system to also log this error?here an code sample:Dim errorText As String = "Doing Something"Try 'Do Something

[Code]...

View 2 Replies

Catch Exception Only In Release?

May 28, 2010

I have one global generic exception handler(catch ex as Exception) for all unhandled exceptions from application.But in debug mode(app runs from VS) I don`t want that exceptions go to this global handler.Better for me is when VS stops app on place when exception occurs.

View 2 Replies

Using Catch For An Exception That Does Not Occur

Mar 25, 2012

What is the code that I can use to describe what happens when there is not just one exception in a'Try...Catch..Finally...End Try' statement? For example: 'Catch' is used to describe what happens when a certain exception occurs, but what can I use to describe what happens when a certain exception does NOT occur?

View 11 Replies

Changing A PictureBox Image On A SerialPort_DataReceived Event Yields Runtime Error: Invalid Operation Exception Was Unhandled?

Nov 28, 2009

Any thoughts on what might cause a thread error like this?Error:InvalidOperationException was unhandledCross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.

Relavent Code:
Private Sub SerialPort_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

[code].....

View 3 Replies

Catch / Handle And Then Again Throw Exception?

Jun 26, 2009

I ran into an interesting dilemna today. I have a function that handles information and checks for duplicate values, then returns the next number that is not a duplicate. So, I have something like this:

Public Function GetNextNonDuplicateNumber(NumberToCheck as Long) as Long
//the non-duplicate the function will return
Dim NonDuplicate as Long
'duplicate
If CheckForDuplicate(NumberToCheck) = True Then
Throw New DuplicateException()
[Code] .....

As you can see, I want to handle the exception specifically, but I also want to throw it when I'm done because I want to alert other code outside the function. The problem is that simply throwing it exits out of the function with a null value.

View 2 Replies

Catch An Exception Generated On Another Thread?

Jan 15, 2011

How do you catch an exception generated on another thread

View 12 Replies

Exception Handling - Can't Catch COMException

Feb 24, 2012

I use the following code to access a VSS item:

Dim sItem As String = "$/MyVssProject/InexistentFile.txt"
Dim oItem As SourceSafeTypeLib.VSSItem = Nothing
Try

[Code]....

The problem I face is when I try to get an instance to a file that doesn't exist in the VSSDB, thus leading to a COMException, which basically wouldn't be of a problem (I would expect). In fact the exception occurs, but instead of proceeding with the catch code, the debug cursor stays on the line "oItem = m_oSourceSafe.VSSItem(sItem)", showing a dialog with title "COMException crossed a native/managed boundary.

From here the execution doesn't proceed, until I change the content of sItem to an existing file.

Why does the exception not get caught, and how can I achieve it?

Environment: VS2010 with .Net 2.0 on WinXP SP3 x86

View 1 Replies

Catch An Exception Thrown By JIRA SOAP?

Oct 17, 2011

I want to catch the exceptions thrown by the login() function in JIRA's SOAP API. The function login throws 2 exceptions. RemoteAuthenticationException if the user provided an invalid username or password and RemoteException if there was some problem preventing the operation from working. Currently I'm using this code to catch the exception

[Code]...

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved