c# 错误立即使程序崩溃
c# fault instantly crashes program
//interface
[OperationContract]
[FaultContract(typeof(UserManagementFault))]
void AddUser(User user);
//class implements interface
public void AddUser(User user)
{
//throw faultException (instant crash)
throw new FaultException<UserManagementFault>(new UserManagementFault("User Excists"),
new FaultReason("User Excists"));
}
//fault
[DataContract]
public class UserManagementFault
{
private string _message;
public UserManagementFault(string message)
{
_message = message;
}
[DataMember]
public string Message { get { return _message; } set { _message = value; } }
}
//method invoker
try {
AddUser();
} catch(FaultException<UserManagementFault>) {
}
throw new FaultException 行执行时程序崩溃,但我希望程序跳转到代码底部的catch 部分。
我做错了什么??
编辑:我注意到 Visual Studio 正在暂停程序,但是当我按下“继续”时,程序进入了 catch 块...奇怪
您的自定义异常代码中似乎有问题。我也会添加一个一般例外以查看发生了什么
try {
AddUser();
} catch(FaultException<UserManagementFault>) {
}
catch(Exception ex) {
}
//interface
[OperationContract]
[FaultContract(typeof(UserManagementFault))]
void AddUser(User user);
//class implements interface
public void AddUser(User user)
{
//throw faultException (instant crash)
throw new FaultException<UserManagementFault>(new UserManagementFault("User Excists"),
new FaultReason("User Excists"));
}
//fault
[DataContract]
public class UserManagementFault
{
private string _message;
public UserManagementFault(string message)
{
_message = message;
}
[DataMember]
public string Message { get { return _message; } set { _message = value; } }
}
//method invoker
try {
AddUser();
} catch(FaultException<UserManagementFault>) {
}
throw new FaultException 行执行时程序崩溃,但我希望程序跳转到代码底部的catch 部分。 我做错了什么??
编辑:我注意到 Visual Studio 正在暂停程序,但是当我按下“继续”时,程序进入了 catch 块...奇怪
您的自定义异常代码中似乎有问题。我也会添加一个一般例外以查看发生了什么
try {
AddUser();
} catch(FaultException<UserManagementFault>) {
}
catch(Exception ex) {
}