A Tour of Go Errors
An error is anything that can describe itself as an error string. The idea is captured by the predefined, built-in interface type, error
, with its single method, Error
, returning a string:
type error interface {
Error() string
}
The fmt
package's various print routines automatically know to call the method when asked to print an error
.
package main import (
"fmt"
"time"
) type MyError struct {
When time.Time
What string
} func (e *MyError) Error() string {
return fmt.Sprintf("at %v, %s",
e.When, e.What)
} func run() error {
return &MyError{
time.Now(),
"it didn't work",
}
} func main() {
if err := run(); err != nil {
fmt.Println(err)
}
}
A Tour of Go Errors的更多相关文章
- A Tour of Go Exercise: Errors
Copy your Sqrt function from the earlier exercises and modify it to return an error value. Sqrt shou ...
- exercise.tour.go google的go官方教程答案
/* Exercise: Loops and Functions #43 */ package main import ( "fmt" "math" ) fun ...
- Referenced file contains errors (http://www.springframework.org/schema...错误
Referenced file contains errors (http://www.springframework.org/schema...错误 Referenced file contains ...
- POJ 1637 Sightseeing tour
Sightseeing tour Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9276 Accepted: 3924 ...
- How the problem solved about " Dealing with non-fast-forward errors"
Recently ,I got confused When I use git to push one of my project. The problem is below: And I Foun ...
- Euler Tour Tree与dynamic connectivity
Euler Tour Tree最大的优点就是可以方便的维护子树信息,这点LCT是做不到的.为什么要维护子树信息呢..?我们可以用来做fully dynamic connectivity(online) ...
- Errors occurred during the build. Errors running builder 'JavaScript Validator' on project
1.问题:Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 2.解决 ...
- publishing failed with multiple errors resource is out of sync with the file system--转
原文地址:http://blog.csdn.net/feng1603/article/details/7398266 今天用eclipse部署项目遇到"publishing failed w ...
- 架构验证过程发现非数据类型错误 validation found non-data type errors
问题: infopath报一下错误 validation found non-data type errors 架构验证过程发现非数据类型错误 原因: 重复表字段在后台代码里要一一对应,否则报错. 错 ...
随机推荐
- Java将整个文件夹里的文本中的字符串替换成另外一个字符串(可用于项目复制,变成另一个项目)
import org.junit.Test; import java.io.*; /** * User: HYY * Date: 13-8-18 * Time: 下午8:11 * To change ...
- MVC 文件上传和图片剪辑
http://www.cnblogs.com/hinton/archive/2012/03/01/2375465.html http://gallery.kissyui.com/uploader/1. ...
- 【POJ】3294 Life Forms
后缀数组. /* 3294 */ #include <iostream> #include <sstream> #include <string> #include ...
- [ffmpeg 扩展第三方库编译系列] 关于libvpx mingw32编译问题
在编译libvpx的时候遇到挺多的问题, 1.[STRIP] libvpx.a < libvpx_g.a strip: Bad file number 这个错误也是比较难搞的,一开始以为只是 ...
- Android开发之xUtils-HttpUtils的使用
使用xUtils框架中的网络部分HttpUtils,功能:下载,断点续传,progressbar显示进度,文本显示进度% import java.io.File; import android.app ...
- Android开发之ListView-SimpleAdapter的使用
SimpleAdapter: SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int r ...
- Eclipse导入项目
导入Eclipse项目 File->Import...->Existing Projects into Workspace->Next->Browse...->Finis ...
- poj 1442 Black Box(堆 优先队列)
题目:http://poj.org/problem?id=1442 题意:n,m,分别是a数组,u数组的个数,u[i]w为几,就加到a几,然后输出第i 小的 刚开始用了一个小顶堆,超时,后来看了看别人 ...
- SDOI2008Cave 洞穴勘测
无限膜拜CLJ大牛…… 不会动态树的弱弱在CLJ的帮助下AC了此题 我想到了并查集(人人都会想到的吧……囧),但不知道应该如何处理destroy操作…… 其实 make操作的实质就是:把x节点到其所在 ...
- linux watchdog demo hacking
/********************************************************************** * linux watchdog demo hackin ...