Errors handling
In order to support Method Chaining calls, most ImGo methods do not return parameters with error information.
When a error occurs, ImGo collects the error information and prints it on the console. Calling other ImGo methods after the method that occur error will not take effect.
However, we still have a way to judge whether the ImGo method if occur errors, as shown in the following example.
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 has an Error attribute, which is used to record the error information during the method call process of imgo. When the attribute is not nil, it indicates that errors has occurred.
After running the above example, the output on console is as follows.
[IMGO] 2022/06/18 17:03:57 /Users/wenyu/go/pkg/mod/github.com/fishtailstudio/[email protected]/loader.go:100 Error: open gopher.jpg: no such file or directory
error: /Users/wenyu/go/pkg/mod/github.com/fishtailstudio/[email protected]/loader.go:100 Error: open gopher.jpg: no such file or directory
Copy link