Solved

Handle exception setting radio button selected item

Posted on 2010-08-24
5
421 Views
Last Modified: 2012-05-10
The code below returns an 'Object reference not set to an instance of an object' error if the TopicData value is no longer an option on the rg radio button list.

I'm not sure how to handle this exception - try/catch does not seem to work.

can someone help?

Thanks.


drFound = topicDetailsTable.Rows.Find(row.Row("ID"))
 If Not (drFound Is Nothing) Then
    rg.Items.FindByValue(drFound("TopicData")).Selected = True
 End If

Open in new window

0
Comment
Question by:sailing_12
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:almander
ID: 33514763
Can you post the code with the non working Try/Catch?
0
 

Author Comment

by:sailing_12
ID: 33514861
Attached.

Still get server error with this in place.
drFound = topicDetailsTable.Rows.Find(row.Row("ID"))
If Not (drFound Is Nothing) Then
    Try
        rg.Items.FindByValue(drFound("TopicData")).Selected = True
    Catch ex As System.Web.Services.Protocols.SoapException
        CrmServiceUtility.LogError(IO.Path.GetFileName(Request.PhysicalPath) + " | " + System.Reflection.MethodBase.GetCurrentMethod().Name, ex)
    End Try
End If

Open in new window

0
 
LVL 1

Expert Comment

by:narendragummadi
ID: 33520913
Try this way
Try
drFound = topicDetailsTable.Rows.Find(row.Row("ID"))
If Not (drFound Is Nothing) Then
        rg.Items.FindByValue(drFound("TopicData")).Selected = True
End If
Catch ex As System.Web.Services.Protocols.SoapException       
	'Your Handling Code
End Try

Open in new window

0
 

Author Comment

by:sailing_12
ID: 33521592
Nope - Still returns error:


Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 2806: drFound = topicDetailsTable.Rows.Find(row.Row("ID"))
Line 2807: If Not (drFound Is Nothing) Then
Line 2808: rg.Items.FindByValue(drFound("TopicData")).Selected = True
Line 2809: End If
Line 2810: Catch ex As System.Web.Services.Protocols.SoapException

0
 
LVL 5

Accepted Solution

by:
almander earned 400 total points
ID: 33524828
This is telling you that TopicData does not exist in the dsFround row.

Your catch is only catching SoapExceptions

You need to add a catch for other exceptions.
Try
drFound = topicDetailsTable.Rows.Find(row.Row("ID"))
If Not (drFound Is Nothing) Then
        rg.Items.FindByValue(drFound("TopicData")).Selected = True
End If
Catch ex As System.Web.Services.Protocols.SoapException       
	'Your Handling Code
Catch exGeneral As Exception
 'Your handling code
End Try

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC - Views 3 38
Validating textboxes in red square borders. 2 32
SSIS GUID Variable 2 30
Error building VS2105 solution from repository 1 31
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question