# error interface

Published articles for error interface.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Interfaces 101 : Error Handling With Go Ep. 3

DevFeed: [Interfaces 101 : Error Handling With Go Ep. 3](<https://devfeed.tech/articles/interfaces-101-error-handling-with-go-ep-3-22213.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/02/interfaces-101-error-handling-with-go.html>)

Published: 2023-02-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>)

Tags: [compiler](<https://devfeed.tech/tags/compiler.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [error-interface](<https://devfeed.tech/tags/error-interface.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [false-positives](<https://devfeed.tech/tags/false-positives.md>), [go](<https://devfeed.tech/tags/go.md>), [go-error-handling](<https://devfeed.tech/tags/go-error-handling.md>), [golang](<https://devfeed.tech/tags/golang.md>), [implement](<https://devfeed.tech/tags/implement.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [video](<https://devfeed.tech/tags/video.md>)

### AI overview

This video explains Go error interfaces through a custom error type and a test that unexpectedly fails when the returned error appears to be nil. It covers how Go determines whether an interface value is nil and how to avoid false positives in custom interface implementations.

### Source excerpt

Introduction In episode 2, Miki examined the impact interfaces have on the performance of a Go program. To perform this experiment, Miki invoked a type's method in two ways: with the concrete type and as an interface function to measure the difference in execution time. The conclusion of this experiment was that calling a method with the concrete type is faster than using an interface. During the experiment, Miki made use of the build flag -gcflag='-m' to display which variables were being allocated on the heap and where the compiler was automatically inlining function calls.

## Error Handling In Go, Part II

DevFeed: [Error Handling In Go, Part II](<https://devfeed.tech/articles/error-handling-in-go-part-ii-22107.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2014/11/error-handling-in-go-part-ii.html>)

Published: 2014-11-10T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Error Handling](<https://devfeed.tech/topics/error-handling.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [error-interface](<https://devfeed.tech/tags/error-interface.md>), [errors](<https://devfeed.tech/tags/errors.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [interface](<https://devfeed.tech/tags/interface.md>), [library](<https://devfeed.tech/tags/library.md>), [packages](<https://devfeed.tech/tags/packages.md>), [pointers](<https://devfeed.tech/tags/pointers.md>), [programming](<https://devfeed.tech/tags/programming.md>), [standard](<https://devfeed.tech/tags/standard.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [types](<https://devfeed.tech/tags/types.md>)

### AI overview

This tutorial explains when custom error types in Go are useful, especially when callers need additional context for error-handling decisions. It examines the standard library's net package and its OpError type, then discusses identifying concrete values stored in error interfaces.

### Source excerpt

Introduction In part I of this post, we learned about the error interface and how the standard library provides support for creating error interface values via the errors package. We also learned how to work with error interface values and use them to identify when an error has occured. Finally, we saw how some packages in the standard library export error interface variables to help us identify specific errors.

## Error Handling In Go, Part I

DevFeed: [Error Handling In Go, Part I](<https://devfeed.tech/articles/error-handling-in-go-part-i-22106.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2014/10/error-handling-in-go-part-i.html>)

Published: 2014-10-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>), [Library](<https://devfeed.tech/topics/library.md>), [HTTP](<https://devfeed.tech/topics/http.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [error-interface](<https://devfeed.tech/tags/error-interface.md>), [errors](<https://devfeed.tech/tags/errors.md>), [function](<https://devfeed.tech/tags/function.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [http](<https://devfeed.tech/tags/http.md>), [interface](<https://devfeed.tech/tags/interface.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [library](<https://devfeed.tech/tags/library.md>), [programming](<https://devfeed.tech/tags/programming.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [types](<https://devfeed.tech/tags/types.md>)

### AI overview

This tutorial explains idiomatic error handling in Go. It covers returning the error interface, checking for nil errors, and how the standard library's errorString struct implements that interface.

### Source excerpt

Introduction It is idiomatic in Go to use the error interface type as the return type for any error that is going to be returned from a function or method. This interface is used by all the functions and methods in the standard library that return errors. For example, here is the declaration for the Get method from the http package: Listing 1.1

## Understanding Defer, Panic and Recover

DevFeed: [Understanding Defer, Panic and Recover](<https://devfeed.tech/articles/understanding-defer-panic-and-recover-22053.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/06/understanding-defer-panic-and-recover.html>)

Published: 2013-06-08T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [code](<https://devfeed.tech/tags/code.md>), [defer](<https://devfeed.tech/tags/defer.md>), [error-interface](<https://devfeed.tech/tags/error-interface.md>), [function](<https://devfeed.tech/tags/function.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

This tutorial explains how Go's defer mechanism works, including how a deferred function runs when its containing function ends and can access captured state through a closure. It introduces defer, panic, and recover as the basis for try/catch-like protection in Go applications.

### Source excerpt

I am building my TraceLog package and it is really important that the package logs any internal exceptions and prevents panics from shutting down the application. The TraceLog package must never be responsible for shutting down an application. I also have internal go routines that must never terminate until the application is shut down gracefully. Understanding how to use Defer and Recover in your application can be a bit tricky at first, especially if you are used to using try/catch blocks. There is a pattern you can implement to provide that same type of try/catch protection in Go. Before I can show you this you need to learn how Defer, Panic and Recover work. First you need to understand the intricacies of the keyword defer. Start with this piece of code: package main import ( "fmt" ) func main() { test() } func mimicError(key string) error { return fmt.Errorf("Mimic Error : %s", key) } func test() { fmt.Println("Start Test") err := mimicError("1") defer func() { fmt.Println("Start Defer") if err != nil { fmt.Println("Defer Error:", err) } }() fmt.Println("End Test") } The MimicError function is a test function that will be used to simulate an error. It is following the Go convention of using the error type to return an indication if something went wrong. In Go the error type is defined as an interface: type error interface { Error() string } If you don't understand what a Go interface is at the moment then this might help for now. Any type that implements the Error() function implements this interface and can be used as a variable of this type. The MimicError function is using errors.New(string) to create an error type variable. The errors type can be found in the errors package. Test function produces the following output: Start Test End Test Start Defer Defer Error : Mimic Error : 1 When you study the output you see that the Test function started and ended. Then right before the Test function terminated for good, the inline defer function was called. Two inter