gpt4 book ai didi

c# - 找不到“ApplicationException”

转载 作者:行者123 更新时间:2023-11-30 19:24:43 27 4
gpt4 key购买 nike

Printscreen我的代码错误和我的引用资料。“ApplicationException”有错误,我只是不知道如何解决它。

using System;
using System.Net;
using System.Net.Http;


namespace Sharepoint_2013_REST_API
{
public class Program
{
public void Main(string[] args)
{
//Init
string baseURL = "hello";
string uriString = "world";

System.Net.Http.HttpClient _Client = new System.Net.Http.HttpClient();
_Client.BaseAddress = new Uri(baseURL);
HttpResponseMessage resp = _Client.GetAsync(uriString).Result;
string respString = resp.Content.ReadAsStringAsync().Result;
if (resp.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException("BAD");
}
}
}
}

错误通知:

Error CS0246 The type or namespace name 'ApplicationException' could not be found (are you missing a using directive or an assembly reference?) 25

最佳答案

ApplicationException类在可移植类库和 ASP.NET vNext 项目中不可用,我认为您的项目是。

更重要的是:

You should derive custom exceptions from the Exception class rather than the ApplicationException class. You should not throw an ApplicationException exception in your code, and you should not catch an ApplicationException exception unless you intend to re-throw the original exception.

所以当你抛出异常时使用Exception

关于c# - 找不到“ApplicationException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33824769/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com