Web 服务对象处理失败
本文关键字:失败 处理 对象 服务 Web | 更新日期: 2023-09-27 18:34:08
我在 C# 中创建对象时遇到关于尝试捕获的问题。
当应该创建一个对象并且定义对象的 Web 服务不可用或已被修改时,会出现我的问题。这就是我希望我的程序处理的问题。
当我尝试这样做时:
try
{
var Customer = new Customer();
}
catch
{
//handling the exception.
}
稍后在我的程序中,我需要该特定对象,但由于 try catch,该对象并非在所有情况下都可用(当然,当 try 失败时,不会创建该对象)。
没有 if(客户 != 空)
if (insertCustomer(lead, LS_TS, out Customer) == true)
{
insert = true;
}
使用 if(客户 != 空)
if(customer != null)
{
if (insertCustomer(lead, LS_TS, out Customer) == true)
{
insert = true;
}
}
无论如何,编译器说:"'客户'这个名字在当前上下文中不存在。
如何解决此问题?我需要一个程序一直在运行,当检查未创建的对象时,我需要退出该方法并稍后重试。
提前致谢
你可以这样做:
Customer customer = null;
try
{
customer = new Customer();
}
catch
{
// handling the exception.
}
每当您需要使用对象客户时,都应该这样做
if(customer != null)
{
// do stuff
}