Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

FError

FError() --> nRet

Retrieves the last file-operation diagnostic.

FErrorAdvPL
01 · OVERVIEW

Overview

FError returns a code for the last file operation, with zero indicating no error. Capture it immediately after failure; closing another handle first can change the diagnostic reference. Official descriptions vary by platform, so codes are not universal errno values. The example deliberately closes invalid handle -1 without touching a valid file. FClose documentation confirms this case, but no portable numeric error is assumed here. (TOTVS, n.d., ref. 1)

02 · SYNTAX

Syntax

FError() --> nRet

Return value

Numeric code; zero indicates no error.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
#Include "Fileio.ch"

User Function Ed381()
    Local nError
    // -1 is not a valid handle; inspect the diagnostic immediately.
    If !FClose(-1)
        nError := FError()
        ConOut(cValToChar(nError))
    EndIf
Return Nil
Expected result

Implementation-specific failure code; no valid handle closed. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Check path, permissions, platform and handle ownership. Close only handles obtained by this routine, including complete-application error handling.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. FError. TDN. Accessed on 2026-10-26.
  2. TOTVS. FClose. TDN. Accessed on 2026-10-26.
  3. EURAI. ADVPL/Funcoes/Arquivos de Disco/FError.PRW. universo_do_desenvolvedor_site, commit a5c83e9490302bdb4a0fc5a9d92c2d569a60773c. Exemplo analisado. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha