I am trying to connect to the server via HttpClient
try { HttpClient httpclient = new HttpClient(); var result = await httpclient.GetStringAsync("Адрес"); dynamic x = Newtonsoft.Json.JsonConvert.DeserializeObject(result); Temperature = x.main.temp; }In the line "Address" I write the wrong way to raise and catch an exception ...
catch (Exception httpex) { throw new HttpException("Не удалось выполнить подключение к узлу", httpex.InnerException, httpex.Source); }I pass the information to my own class HttpException , where I call the method (and pass parameters to it), which writes to the xml file.
[Serializable] public class HttpException : Exception { public HttpException() { } public HttpException(string message) : base(message) { } public HttpException(string message, Exception inner, string source) :base(message, inner) { XmlLog.Write(message, inner, source); } protected HttpException( System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
So here. After writing to the xml file, the statement returns to the line where the exception was initialized.
throw new HttpException("Не удалось выполнить подключение к узлу", httpex.InnerException, httpex.Source); And then it throws me an exception, where it says that my own "HttpException" exception was not handled by the user. I just can not understand where I make a mistake. Judging by the debugging, everything that happens in my class (HttpException), including working with xml, happens without errors.
catch /*без параметров*/ { /* и breakpoint вот здесь */ }to the tailcatch /*без параметров*/ { /* и breakpoint вот здесь */ }- VladDthrow new HttpException(...)=выбросить новое исключение_имеющее_класс_HttpException- 4per 10:51 pm... чтобы вызвать и словить исключение ...Then there is an excerpt of the text of the program in which you really have toвызвать, but where is theсловить? If you don’t have aсловить, it means that it’s runtime and will correctly report that he had to catch him instead of the user. - Sergey