Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
error.go43 linesDownload Raw Back to gob
1// Copyright 2009 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4 5package gob6 7import "fmt"8 9// Errors in decoding and encoding are handled using panic and recover.10// Panics caused by user error (that is, everything except run-time panics11// such as "index out of bounds" errors) do not leave the file that caused12// them, but are instead turned into plain error returns. Encoding and13// decoding functions and methods that do not return an error either use14// panic to report an error or are guaranteed error-free.15 16// A gobError is used to distinguish errors (panics) generated in this package.17type gobError struct {18	err error19}20 21// errorf is like error_ but takes Printf-style arguments to construct an error.22// It always prefixes the message with "gob: ".23func errorf(format string, args ...any) {24	error_(fmt.Errorf("gob: "+format, args...))25}26 27// error_ wraps the argument error and uses it as the argument to panic.28func error_(err error) {29	panic(gobError{err})30}31 32// catchError is meant to be used as a deferred function to turn a panic(gobError) into a33// plain error. It overwrites the error return of the function that deferred its call.34func catchError(err *error) {35	if e := recover(); e != nil {36		ge, ok := e.(gobError)37		if !ok {38			panic(e)39		}40		*err = ge.err41	}42}43 
codekingpro/portable-devtools · Team Ai