基类:RfcBaseException nco3.0中异常的基类是RfcBaseException, 继承自ApplicationException。其他一些重要的异常类说明如下: 其他常见异常类RfcCommunicationException- 继承自RfcBaseException
- 与后台SAP系统通讯失败时,引发此异常,比如网络问题,SAP服务器没有启动等。
RfcLogonException- 继承自RfcBaseException
- SAP系统拒绝用户登录,比如密码错误等引发的异常。
RfcInvalidParameterException- 继承自RfcBaseException
- 如果参数不存在,或者参数名不正确,会引发该异常。
RfcAbapBaseException- 继承自RfcBaseException, 是Abap异常的基类
示例
using System;
using SAP.Middleware.Connector;
namespace NCo03
{
public class ExceptionHandlingDemo
{
public void WriteTCPIC()
{
// the folowing lines will be added to TCPIC table in SAP system
String[] lines = new String[] {
"轻轻的我走了,",
"正如我轻轻的来,",
"我轻轻的招手,",
"作别西天的云彩。"};
try {
RfcDestination dest = NCo02.DestinationProvider.GetDestination();
IRfcFunction fm = dest.Repository.CreateFunction("STFC_WRITE_TO_TCPIC");
IRfcTable tcpicData = fm.GetTable("TCPICDAT");
tcpicData.Append(lines.Length); // insert lines according to lines.Length
for (int i = 0; i < lines.Length; i++) {
tcpicData.SetValue("LINE", lines);
}
fm.Invoke(dest);
}
catch (RfcCommunicationException ex) {
// network problem
System.Console.WriteLine(ex.ToString());
}
catch (RfcLogonException ex) {
// user could not log on
System.Console.WriteLine(ex.ToString());
}
catch (RfcAbapBaseException ex) {
// ABAP excpeption
System.Console.WriteLine(ex.ToString());
}
}
}
}
说明- STFC_WRITE_TO_TCPIC函数将字串中插入到TCPIC表中,函数适合做演示之用
- 如果插入table parameter的参数有规律,可以参考本例中的代码
NCo3.0系列的参考文档
|