(1)什么错误表示服务器失败?
(2)数据库(SQL Server, ADO)错误代码与HResult关系?
(3)那些范围可以自定义使用?

解决方案 »

  1.   

    以前没有仔细考虑过:
    The following HRESULT values are defined in the System unit:Constant Hex. Value MeaningS_OK 00000000 No error. In some APIs, S_OK indicates a successful operation with a return value of true.
    S_FALSE 00000001 No error, but operation did not produce a useful result. In some APIs, S_FALSE indicates a successful operation with a return value of false.
    E_INTERFACE 80004002 Interface not supported.
    E_UNEXPECTED 8000FFFF Catastrophic failure
    E_NOTIMPL 80004001 Operation not implementedNote that in the above constant names, the S_ and E_ prefixes correspond to the value of the Severity bit.The following HRESULT values are defined in the Types unit (Linux) or Windows unit (Windows):Constant Hex. Value MeaningE_FAIL 80004005 Unspecified error.STG_E_INVALIDFUNCTION 80030001 Unable to perform storage management function.
    STG_E_FILENOTFOUND 80030002 File not found.
    STG_E_PATHNOTFOUND 80030003 Path not found.
    STG_E_TOOMANYOPENFILES 80030004 Insufficient resources to open another file.
    STG_E_ACCESSDENIED 80030005 Access denied.
    STG_E_INSUFFICIENTMEMORY 80030008 Insufficient memory to complete storage operation.
    STG_E_NOMOREFILES 80030012 No more files to return.
    STG_E_DISKISWRITEPROTECTED 80030013 Disk is write-protected.STG_E_SEEKERROR 80030019 Error during seek.
    STG_E_LOCKVIOLATION 80030021 Lock violation.
    STG_E_FILEALREADYEXISTS 80030050 File already exists.
    STG_E_INVALIDPARAMETER 80030057 Invalid parameter.
    STG_E_MEDIUMFULL 80030070 Disk full.
    STG_E_INVALIDNAME 800300FC Invalid name.
    Note that an additional prefix is added to HRESULT constant names to indicate a non-zero Facility Code. In the above examples, the STG_ prefix and the Facility Code 3 both indicate storage errors.和数据库的errorcode应该没有直接的联系
      

  2.   

    to: del_c_sharp(摩托~◎~◎~◎),多谢!请问HResult整体是如何划分的?我的目的:
    (1)我想确定服务器失败,总不能按李维所例,
         凡OleSysError都视为服务器失败吧。
    (2)数据库操作异常时错误代码是否转换成对应的HResult,
         以便在Client判断。
    (3)用系统未使用的错误代码,自定义含义,以便在Client
         做出相应处理。
      

  3.   

    想法不错~不过可以直接自定义一个out参数吧,比这样要稳定而且好控制吧
      

  4.   

    最好的办法是把异常包装为HResult返回(DELPHI的SAFECALL自动实现这一功能)
      

  5.   

    find an anwser:server
    -----------------
    uses ComServ;const
      CODE_BASE = $200; //recommended codes are from 0x0200 - 0xFFFFprocedure TFoo.Bar;
    begin
      //can be assigned once (globally) from somewhere
      ComServer.HelpFileName := 'HelpFile.hlp';  //help file
      //raise error: message='Error Message', number=5 + CODE_BASE, help context=1
      raise EOleSysError.Create (
        'Error Message', //error message
        ErrorNumberToHResult (5 + CODE_BASE), //HRESULT
        1 //help context
        );
    end;function ErrorNumberToHResult (ErrorNumber : integer) : HResult;
    const
      SEVERITY_ERROR = 1;
      FACILITY_ITF = 4;
    begin
      Result := (SEVERITY_ERROR shl 31) or (FACILITY_ITF shl 16) or word (ErrorNumber);
    end;
    -----------------
    client
    -----------------
    const
      CODE_BASE = $200; //recommended codes are from 0x0200 - 0xFFFFprocedure CallFooBar;
    var
      Foo : IFoo;
    begin
      Foo := CoFoo.Create;
      try
        Foo.Bar;
      except
        on E : EOleException do
          ShowMessage ('Error message: ' + E.Message + #13 +
            'Error number: ' + IntToStr (HResultToErrorNumber (E.ErrorCode) - CODE_BASE) + #13 +
            'Source: ' + E.Source + #13 +
            'HelpFile: ' + E.HelpFile + #13 +
            'HelpContext: ' + IntToStr (E.HelpContext)
            );
      end;
    end;function HResultToErrorNumber (hr : HResult) : integer;
    begin
      Result := (hr and $FFFF);
    end;
      

  6.   

    to Raptor(猛禽) and del_c_sharp(摩托~◎~◎~◎):在有理由解脱自己的时候,你们还在网上,为我等提供帮助,
    非常感谢!!! 而我睡了一个懒觉,不好意思。今天继续工作,我试试看:
    主要是确定服务器失败,以便做容错处理。