Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > VB.NET General Discussion

VB.NET General Discussion VB.NET general discussion area

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2008, 2:51 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Location: USA
Age: 22
Posts: 14
Reputation: 18
Spilled is on a distinguished programming path ahead
Default WebException Throws NullReferenceException

Hello all when I try to Handle my WebException I'm getting a NullReferenceException when I try to Display the Error. Here is my code:

Code:
            Try
                res = req.GetResponse()
                RaiseEvent UpdateResponse(threadID, res.StatusCode.ToString & " - " & res.StatusDescription)
                res.Close()
            Catch Err As WebException
                If Err.Status = WebExceptionStatus.ProtocolError Then
                    RaiseEvent UpdateResponse(threadID, "401 - Unauthorised")
                Else
                    RaiseEvent UpdateResponse(threadID, CType(Err.Response, HttpWebResponse).StatusCode.ToString & " - " & CType(Err.Response, HttpWebResponse).StatusDescription)
                    RetryComboNeedNewProxy = True
                End If
            End Try
RaiseEvent UpdateResponse(threadID, CType(Err.Response, HttpWebResponse).StatusCode.ToString & " - " & CType(Err.Response, HttpWebResponse).StatusDescription)
Is where i get the NullReferenceException, Err.response is "nothing" in the debugger, WebException.Response suppose to return the WebResponse type of the exception? Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-02-2008, 5:40 AM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 6,098
Reputation: 540
jmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalist
Default

The documentation indicates that if the Status IS ProtocolError then Response will contain a WebResponse. You're trying to get Response when Status is NOT ProtocolError, in which case it's obviously not guaranteed to not be Nothing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-02-2008, 6:13 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Location: USA
Age: 22
Posts: 14
Reputation: 18
Spilled is on a distinguished programming path ahead
Default

o ic, so what is the response when it is NOT protocol error? A timeout?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-02-2008, 6:32 AM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 6,098
Reputation: 540
jmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalist
Default

Um, obviously in your case it's Nothing. Have you checked what the actual status is? Maybe that will give you a clue what the issue is. After all, for some errors it should be obvious that there'd be no response because the server couldn't have responded.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 6:33 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.