Files
five/hbrtl/error.go
Charles KWON OhJun 59568f3301 Five v0.9 — Harbour + Go fusion language
- Compiler: PP → Lexer → Parser → Analyzer → Gengo pipeline
- Parser: 232/236 (98%) Harbour compatibility, registry-based dispatch
- RTL: 351 Harbour-compatible functions
- RDD: DBF/NTX/CDX engines with Rushmore bitmap optimization
- Go Interop: IMPORT + pkg.Func() + obj:Method() with FastPath (15M calls/sec)
- HB_FUNC API: Full Harbour C API compatible Go bridge
- Concurrency: SPAWN/LAUNCH/GOROUTINE, <-, WATCH, PARALLEL FOR, ASYNC/AWAIT
- Extensions: Multi-return, DEFER, Slice, f-string, Nil-safe ?:, CONST
- Macro Compiler: Runtime AST parsing and evaluation
- Debugger: TUI debugger with source display, breakpoints, stepping
- FRB: Native + Pcode dual mode runtime binary
- Tests: 13 packages ALL PASS

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:41:50 +09:00

97 lines
2.3 KiB
Go

// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
// All rights reserved.
// Error handling functions: ERRORBLOCK, ERRORNEW, DOSERROR, FERROR
// Harbour error system: Error object + ErrorBlock callback chain.
package hbrtl
import (
"five/hbrt"
)
var (
errorBlock hbrt.Value // current error handler block
lastDosErr int // last OS error code
lastFErr int // last file error code
)
// ERRORBLOCK([bNewBlock]) → bOldBlock
// Gets/sets the error handler code block.
func ErrorBlock(t *hbrt.Thread) {
nParams := t.ParamCount()
t.Frame(nParams, 0)
defer t.EndProc()
old := errorBlock
if old.IsNil() {
old = hbrt.MakeNil()
}
if nParams >= 1 && !t.Local(1).IsNil() {
errorBlock = t.Local(1)
}
t.RetVal(old)
}
// ERRORNEW() → oError
// Creates a new Error object as a hash with standard Harbour error properties.
func ErrorNew(t *hbrt.Thread) {
t.Frame(0, 0)
defer t.EndProc()
keys := []hbrt.Value{
hbrt.MakeString("ARGS"), hbrt.MakeString("CANDEFAULT"),
hbrt.MakeString("CANRETRY"), hbrt.MakeString("CANSUBSTITUTE"),
hbrt.MakeString("CARGO"), hbrt.MakeString("DESCRIPTION"),
hbrt.MakeString("FILENAME"), hbrt.MakeString("GENCODE"),
hbrt.MakeString("OPERATION"), hbrt.MakeString("OSCODE"),
hbrt.MakeString("SEVERITY"), hbrt.MakeString("SUBCODE"),
hbrt.MakeString("SUBSYSTEM"), hbrt.MakeString("TRIES"),
}
vals := []hbrt.Value{
hbrt.MakeNil(), hbrt.MakeBool(false),
hbrt.MakeBool(false), hbrt.MakeBool(false),
hbrt.MakeNil(), hbrt.MakeString(""),
hbrt.MakeString(""), hbrt.MakeInt(0),
hbrt.MakeString(""), hbrt.MakeInt(0),
hbrt.MakeInt(2), hbrt.MakeInt(0),
hbrt.MakeString(""), hbrt.MakeInt(0),
}
h := &hbrt.HbHash{Keys: keys, Values: vals}
order := make([]int, len(keys))
for i := range order {
order[i] = i
}
h.Order = order
t.RetVal(hbrt.MakeHashFrom(h))
}
// DOSERROR([nNewCode]) → nOldCode
func DosError(t *hbrt.Thread) {
nParams := t.ParamCount()
t.Frame(nParams, 0)
defer t.EndProc()
old := lastDosErr
if nParams >= 1 && !t.Local(1).IsNil() {
lastDosErr = t.Local(1).AsInt()
}
t.RetInt(int64(old))
}
// FERROR() → nLastFileError
func FError(t *hbrt.Thread) {
t.Frame(0, 0)
defer t.EndProc()
t.RetInt(int64(lastFErr))
}
// SetFError sets the file error code (called internally by file I/O functions).
func SetFError(code int) {
lastFErr = code
}