0

As I'm debugging, I noticed $exception within the locals window as a result of an exception thrown implying this variable is available in the scope.

The question is how can I access this $exception variable.

How can line 78 be?

| x ->  Debug.WriteLine("exception" + $exception.Response.StatusCode)

enter image description here

1 Answer 1

4

You can catch exceptions of a specific type with this syntax:

try
  ...
with
| :? System.Net.WebException as e ->
    let response = e.Response :> System.Net.HttpWebResponse
    Console.WriteLine("exception" + response.StatusCode)

Note you need to cast WebException.Response to System.Net.HttpWebResponse so you can access its StatusCode property.

See the MSDN docs for more.

Sign up to request clarification or add additional context in comments.

1 Comment

It might be worth pointing out that the case to HttpWebResponse can fail: stackoverflow.com/questions/3614034/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.