zoukankan      html  css  js  c++  java
  • 如何处理系统异常

    捕捉具体的异常比较简单,就说下怎么样捕捉系统未知异常。有了以下处理异常的代码,相信系统出现的任何异常,都不会因为我们的程序而dump. 我们用cx_root(RFC需要用exceptions).
    经过测试,db错误,不仅是open-sql,还有native-sql产生的错误都可以处理,还有function参数类型不匹配,function名字错误等都可以处理。如果谁发现有不能处理的异常,请留言。
     
    REPORT  z_victor_pan                           .
    data: name type string.
    DATA: l_oref TYPE REF TO cx_root,
          exception_msg(1000),
          msg(1000).
    class test definition.
    public section. methods ok.
    endclass.
    class test implementation.
    method ok.
    data: a1 type i.
    try.
    a1 = 100 / 0.
    catch cx_root  into l_oref.
    msg = l_oref->get_text( ) .
    write:/ msg.
    endtry.
    endmethod.
    endclass.
    start-of-selection.
     
    try.
      call function 'ZPZTEST_RFC1' destination 'RGSCLNT301'
        IMPORTING
          name                  = name
        EXCEPTIONS
          SYSTEM_FAILURE        = 1  MESSAGE exception_msg
          COMMUNICATION_FAILURE = 2  MESSAGE exception_msg.
      write:/ exception_msg.
      clear: exception_msg, msg.
    endtry.

    try.
        call function 'ZPZTE'.
    *     EXCEPTIONS
    *     SYSTEM_FAILURE = 1 MESSAGE msg.
    *catch CX_SY_DYN_CALL_ILLEGAL_FUNC into l_oref.
      catch cx_root  into l_oref.
        exception_msg = l_oref->get_text( ).
        write:/ msg.
        clear msg.
    endtry.

    try.
        name = 100 / 0.
      catch cx_root into l_oref.
        msg =  l_oref->get_text( ).
        write:/ msg.
    endtry.
    clear msg.
    try.
    name = 100 / 0.
    call function 'ZPZTE'.
    call method CL_GUI_FRONTEND_SERVICES=>(msg).
    catch cx_root into l_oref.
     msg =  l_oref->get_text( ).
        write:/ msg.
    endtry.
    data:  ss type ref to test.
    create object ss.
    try .
    ss->ok( ).
    catch cx_root into l_oref.
    msg =  l_oref->get_text( ).
     write:/ msg.
    endtry.
  • 相关阅读:
    小小c#算法题
    .net中值类型、引用类型理解的c#代码示例
    小小c#算法题
    小小c#算法题
    小小c#算法题
    小小c#算法题
    python 正则表达式(一)
    python string 文本常量和模版
    centos6安装redis
    sqoop命令总结
  • 原文地址:https://www.cnblogs.com/elegantok/p/1572037.html
Copyright © 2011-2022 走看看