//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 块......奇怪
侃侃尔雅
相关分类