> For the complete documentation index, see [llms.txt](https://imgo.gitbook.io/cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://imgo.gitbook.io/cn/usage/errors.md).

# 错误处理

为了支持简洁的链式调用，ImGo 的大部分方法没有返回错误信息的参数。

当发生异常情况时，ImGo 会收集这些错误信息，并打印在命令行。在发生错误的方法之后在调用其他ImGo 方法是不会生效的。

但我们仍然有办法去判断 ImGo 的方法是否发生错误，如下例所示。

```go
package main

import (
    "awesomeProject/imgo"
    "fmt"
)

func main() {
    err := imgo.Load("gopher.jpg").Save("out.png").Error
    if err != nil {
        fmt.Println("error:", err.Error())
    } else {
        fmt.Println("success")
    }
}
```

ImGo 有个 `Error` 属性，用来记录 ImGo 的方法调用过程中的错误信息，当该属性不为 `nil` ，则表示发生了错误。

运行上例后，命令行输出如下。

```
[IMGO] 2022/06/18 17:03:57 /Users/wenyu/go/pkg/mod/github.com/fishtailstudio/imgo@v0.0.1/loader.go:100 Error: open gopher.jpg: no such file or directory
error: /Users/wenyu/go/pkg/mod/github.com/fishtailstudio/imgo@v0.0.1/loader.go:100 Error: open gopher.jpg: no such file or directory
```
