must

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 3 Imported by: 4

Documentation

Overview

Package must is an experiment to see if a concise way to work with panics will break Go's convention to explicitly check for errors as described in https://blog.golang.org/error-handling-and-go. By no means it is a good idea to work against language design. So this is to be handled with care!

Somewhere I read a good advice regarding Go's panic:

Do not expect someone else to recover from your panic!

This is quite in line with the “Don't panic across package boundaries” rule. If you panic across package boundaries you are responsible for the program to crash. This shall be something truly exceptional!

Consider that, when my C++ compiler started to support exception handling (yes exceptions weren't there forever), they explained that C++ exceptions shall represent some truly exceptional program state. But today – also in Java – exceptions are rather common (“exception” / “common” - think about it). They are used for error handling. IMHO Andrei Alexandrescu elaborates on this very nicely in https://www.youtube.com/watch?v=kaI4R0Ng4E8.

Addendum to the license

You must not use this package before you really understand the above advice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(err error)

Do calls panic(err) if err is not nil.

func Ret

func Ret[T any](v T, err error) T

Ret calls panic(err) if err is not nil. Otherwise it returns v.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL