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 架构验证过程发现非数据类型错误 原因: 重复表字段在后台代码里要一一对应,否则报错. 错 ...
随机推荐
- PYTHON设计模式,创建型之工厂方法模式
我感觉和上一个差不多,可能不要动最要的地方吧... #!/usr/bin/evn python #coding:utf8 class Pizza(object): def prepare(self, ...
- linux ubuntu 11.04 samba 服务器设置
安装 SAMBA 组件 sudo apt-get install samba smbfs smbclient 配置相关参数 sudo gedit /etc/samba/smb.conf 文件中相关 ...
- 去除右键菜单opendlg
环境:windows8.1专业版 未知文件类型,右键会多出一个opendlg的选项!下面是移除的方法: 将下面的内容复制到记事本,并另存为XXX .reg,导入注册表即可! Windows Reg ...
- 200. Number of Islands
题目: Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is s ...
- 107. Binary Tree Level Order Traversal II
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
- Uploadify 控件上传图片 + 预览
jquery的Uploadify控件上传图片和预览使用介绍. 在简单的servlet系统中和在SSH框架中,后台处理不同的,在三大框架中图片预览时费了不少力气,所以下面将两种情况都介绍一下. 1,前台 ...
- Vim插件列表
01.helm(Vim-Swoop) 02.ap/vim-buftabline 03.wesleyche/SrcExpl 04.vim proc 05.vim shell 06.dhruvasagar ...
- 2.1 linux中uboot移植
-- --------------------------------------------------------------------------------------- (一)友善之臂介绍 ...
- ADT中的代码补全设置
设置自动补全代码 刚刚学Android,有很多变量和方法 都不熟悉.需要有提示,才更加方便. 快捷方式:Alt + / 可以出现代码提示. 默认的只有输入“ .” 以后才会有代码补全提示,可作如 ...
- Java面试题-并发工具
1. 如何实现一个流控程序,用于控制请求的调用次数?