Skip to content

Commit

Permalink
Edited to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rozturac committed Nov 28, 2021
1 parent 631cc71 commit 5bfb565
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# cerror
Golang Error Handling
# 🥷 CError (Custom Error Handling)

[![GitHub license](https://img.shields.io/github/license/rozturac/cerror.svg?color=24B898&style=for-the-badge&logo=go&logoColor=ffffff)](https://github.com/rozturac/cerror/blob/main/LICENSE)
[![Documentation](https://img.shields.io/badge/godoc-reference-blue.svg?color=24B898&style=for-the-badge&logo=go&logoColor=ffffff)](https://pkg.go.dev/github.com/rozturac/cerror)
[![Release](https://img.shields.io/github/tag/rozturac/cerror.svg?label=release&color=24B898&logo=github&style=for-the-badge)](https://github.com/rozturac/cerror/releases/latest)
[![Go Report Card](https://img.shields.io/badge/go%20report-A%2B-green?style=for-the-badge)](https://goreportcard.com/report/github.com/rozturac/cerror)

## Installation

Via go packages:
```go get github.com/rozturac/cerror```

## Usage

Here is a sample CError uses:

```go
import (
"github.com/rozturac/cerror"
"log"
"strconv"
)

func main() {
defer func() {
if recover := recover(); recover != nil {
if err, ok := recover.(cerror.Error); ok {
log.Fatal(err.ErrorWithTrace())
}
}
}()

x := "23x"
y, err := strconv.Atoi(x)
if err != nil {
panic(cerror.InvalidCastError(x, y).With(err))
}
}
```

Log message:
``` shell
Cannot convert the '23x' value to a int.
strconv.Atoi: parsing "23x": invalid syntax
[main.main] /Users/rozturac/go/src/github.com/cerror/_examples/cmd/main.go:21
```

Console message:
``` shell
Cannot convert the '23x' value to a int.
```

0 comments on commit 5bfb565

Please sign in to comment.