美文网首页
go错误处理

go错误处理

作者: 青哥DevOps | 来源:发表于2021-05-09 22:36 被阅读0次
package main

import "fmt"

type message struct {
    content string
}

func (p *message) set(c string) {
    p.content = c
}

func (p *message) print() string {
    fmt.Println("inner defer func")
    p.content += p.content
    return p.content
}

func main() {
    m := &message{content: "Hello"}
    defer fmt.Println(m.print()) // 结果寄存起来了,不会随后来的改变而改变,然而每次defer都是存储当前的状态
    //defer func() {
    //  fmt.Print(m.print())
    //}()
    fmt.Println(m.content, 111)
    m.set("World")
    fmt.Println("我是有底线的")
    fmt.Println(m.content)

    defer fmt.Println(m.print())
    fmt.Println(222)

}



============================
output:
inner defer func
HelloHello 111
我是有底线的
World
inner defer func
222
WorldWorld
HelloHello

相关文章

  • Go 语言基础——错误处理

    学习目标 掌握错误处理 掌握自定义错误处理 掌握defer关键字的使用 错误处理 GO没有异常处理机制 Go语言引...

  • 2021-06-08

    Go的编程模式,错误处理 引入了其他语言的错误处理模式,最后,说明Go错误处理的好处。主要是将函数的入参、出参、错...

  • Learn Golang in Days - Day 15-Go

    Learn Golang in Days - Day 15-Go错误处理 简介 Go语言通过内置错误接口提供了简单...

  • Go 专栏|错误处理:defer,panic 和 recover

    原文链接: Go 专栏|错误处理:defer,panic 和 recover[https://mp.weixin....

  • golang

    golang go和php的区别类型:go为编译性语言;php解释性语言错误:go的错误处理机制;php本身或者框...

  • Go开发关键技术指南:Errors

    Errors 错误处理是现实中经常碰到的、难以处理好的问题,下面会从下面几个方面探讨错误处理: 为什么Go没有选择...

  • go 语言错误处理

    go 语言错误处理 panic recover defer 最大公约数 最小公倍数 go语言中的没有try cat...

  • 基础-3

    异常处理 error接口:Go中的一个关于错误处理的标准模式,属于Go内建的接口类型;type error int...

  • GO语言学习---chapter13

    第13章 错误处理及检测 20180629 go认为java和.net的try catch finally 那...

  • go语言20小时从入门到精通(九、异常处理)

    9.1 error接口 Go语言引入了一个关于错误处理的标准模式,即error接口,它是Go语言内建的接口类型,该...

网友评论

      本文标题:go错误处理

      本文链接:https://www.haomeiwen.com/subject/itavdltx.html