home *** CD-ROM | disk | FTP | other *** search
- <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <script language="C#" runat="server">
-
- public void Page_Load(Object sender, EventArgs E)
- {
- // shell the explorer to a directory
- Ref.RunSample = Server.MapPath("/quickstart/howto/samples/net/WebRequests");
-
- // run an aspx page directly
- // Ref.RunSample = "/quickstart/howto/samples/BaseDataTypes/Sort/Sort.aspx";
-
- Ref.ViewSource = "/quickstart/howto/samples/net/WebRequests/clientwebexception.src";
- Ref.Icon = "/quickstart/images/genicon.gif";
- Ref.Caption = "ClientException.exe";
- }
-
- </script>
-
- <h4>How Do I...Handle WebException?</h4>
-
- <div class="indent" style="width:660">
- This sample illustrates how to use the WebException class when dealing with exceptions when accessing URIs.
- <BR>
- <P>
- This sample is like the simple clientGET.cs sample, except that it wraps the call in a Try/Catch wrapper.
- 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.
- </P>
- <P>
- In this catch section, the object that is caught is of type
- <B>WebException</B>. This object, WebExcp, has an exception message that can be
- written out with <B>WebExcp.ToString()</B>. In addition, you can examine the
- error code with the call to its <B>Status</B> property. If this status is 7,
- then you can get the WebResponse and see its status code, which will map to an
- HTTP status code.
- </p>
- </div>
-
- <h4>Example</h4>
-
- <Acme:SourceRef id="Ref" runat="server" />
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/net/WebRequests/clientwebexception.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->
-