Reputation: 12599
I'm trying to find the Exceptions that are thrown by HttpClient
's GetAsyncString
method. I've checked the docs on MSDN but I can't seem to find what exceptions are thrown by the method.
Any ideas?
Upvotes: 0
Views: 91
Reputation: 99869
Short answer: The documentation for GetStringAsync
only gives a partial answer to the question. Without clarification from Microsoft, you won't be able to get an official answer to your question. Unofficial answers may help now, but there will not be any guarantee that future releases of the .NET Framework (even patch releases) will preserve the precise exception behavior you observe currently.
Long answer:
One of the outstanding problems for the Task-based Asynchronous Pattern is the question of how exceptions are documented for asynchronous methods. Traditionally, the exception documentation only included exceptions thrown by the synchronous behavior of the method. Unfortunately, this leaves no place for documenting exceptions thrown during the asynchronous behavior of the method, i.e. the exceptions that you'd see only if you look at the Exception
property of the returned Task
, or attempt to await
the task. The MSDN documentation for GetStringAsync
only documents the synchronous exceptions for the method.
So you are aware of one alternative, even though it doesn't address your specific question here, see the section Exceptions Thrown by Asynchronous Methods I wrote for a library I am working on.
Upvotes: 1
Reputation: 700342
I assume that you mean the GetStringAsync
method.
The exceptions are listed in the documentation, it will thow an ArgumentNullException
if the parameter is null.
That doesn't seem to be the entire truth, though. If you look at the example code on the documentation page for the HttpClient
class, the process of making a request can also throw an HttpRequestException
. The reason that it's not listed on the method page is probably that the method call itself will never throw it, it's thrown by the asynchronous process that does the request.
Upvotes: 1
Reputation: 1207
Usually if you search on MSDN for the class and method it will tell you what exceptions that method with itself create, not exceptions that are external to it.
http://msdn.microsoft.com/en-us/library/hh158944(v=vs.110).aspx
Upvotes: 0
Reputation: 6039
Throws ArgumentNullException
(Assume you are talking about GetStringAsync
here).
http://msdn.microsoft.com/en-us/library/hh551746(v=vs.110).aspx
Upvotes: 3