home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / WebRequests / clientException.aspx next >
Encoding:
Text File  |  2000-06-11  |  1.9 KB  |  54 lines

  1. <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
  2.  
  3. <!-- #include virtual="/quickstart/howto/include/header.inc" -->
  4.  
  5. <script language="C#" runat="server">
  6.  
  7.     public void Page_Load(Object sender, EventArgs E) 
  8.     {
  9.         // shell the explorer to a directory
  10.         Ref.RunSample = Server.MapPath("/quickstart/howto/samples/net/WebRequests");
  11.  
  12.         // run an aspx page directly
  13.         // Ref.RunSample = "/quickstart/howto/samples/BaseDataTypes/Sort/Sort.aspx";
  14.  
  15.         Ref.ViewSource = "/quickstart/howto/samples/net/WebRequests/clientwebexception.src";
  16.         Ref.Icon = "/quickstart/images/genicon.gif";
  17.         Ref.Caption = "ClientException.exe";
  18.     }
  19.  
  20. </script>
  21.  
  22. <h4>How Do I...Handle WebException?</h4>
  23.  
  24. <div class="indent" style="width:660">
  25. This sample illustrates how to use the WebException class when dealing with exceptions when accessing URIs.
  26. <BR>
  27. <P>
  28. This sample is like the simple clientGET.cs sample, except that it wraps the call in a Try/Catch wrapper. 
  29. The section of code we care about then (other than adding a try and catch to make sure we catch exceptions) is the catch section.
  30. </P>
  31. <P>
  32. In this catch section, the object that is caught is of type 
  33. <B>WebException</B>. This object, WebExcp, has an exception message that can be 
  34. written out with <B>WebExcp.ToString()</B>. In addition, you can examine the 
  35. error code with the call to its <B>Status</B> property. If this status is 7, 
  36. then you can get the WebResponse and see its status code, which will map to an 
  37. HTTP status code.
  38. </p>
  39. </div>
  40.  
  41. <h4>Example</h4>
  42.  
  43. <Acme:SourceRef id="Ref" runat="server" />
  44.  
  45. <h4>Source Code</h4>
  46.  
  47. <div class="code">
  48. <xmp>
  49. <!-- #include virtual="/quickstart/howto/samples/net/WebRequests/clientwebexception.cs" -->
  50. </xmp>
  51. </div>
  52.  
  53. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->
  54.