首页 > TAG信息列表 > panicking

Why is Go PANICking?

A panic should always be a last resort, and even then consider a better option! Logging errors with context (cause and message) Expose errors as metrics Expose errors as events So after all the long talk, when is it okay to panic? Panics are somewhat

error、panic、recover、panicking

错误处理:当程序处于错误状态可以用os.Exit(1)来中止运行自定义错误:err := errors.New("I am error")用fmt创建错误(和print一个样,它会创建一个自定义error,字符串就是格式化后的字符串)fmt.Errorf("math: square root of negative number %g", f) 运行时异常与panic 当发生运行时错误

Rust 智能指针(二)

1. Rc<T> 引用计数指针 Rc<T> 是引用计数指针,可以使用clone使得指针所指向的数据具有多个所有者。 enum List { Cons(i32, Rc<List>), Nil, } use List::{Cons, Nil}; use std::rc::Rc; fn main() { let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));