Rust中的错误处理
2024-10-08 07:47:22
Result & Panic
这次讲得详细,从错误的来历及简写过程,
都写明白了,
先浅,再深,先深,再浅,
反复之,
学习王道~
use std::fs::File; //use std::io::ErrorKind; fn main() { //panic!("crash and burn"); //let v = vec![1, 2, 3]; //v[99]; /* let f = File::open("hello.txt"); let f = match f { Ok(file) => file, Err(error) => match error.kind() { ErrorKind::NotFound => match File::create("hello.txt") { Ok(fc) => fc, Err(e) => panic!("Try create new file, but error : {:#?}", e), }, other_error => panic!("There was a problem opening the file: {:#?}", other_error), }, }; let f = File::open("hello.txt").map_err(|error| { if error.kind() == ErrorKind::NotFound { File::create("hello.txt").unwrap_or_else(|error| { panic!("Try create new file, but error : {:#?}", error); }) } else { panic!("There was a problem opening the file: {:#?}", error); } }); */ //let f = File::open("hello.txt").unwrap(); let f = File::open("hello.txt").expect("Failed to open hello.txt"); println!("f value is {:#?}", f); }
最新文章
- Hibernate 更新部分字段的实现
- SVN批处理
- linux配置ftp
- RCP:eclipse的DEBUG机制
- 【Java基础】RTTI与反射之Java
- Android 开源项目
- 关于常用的git命令列表
- centos下的lnmp环境搭建
- int, NSInteger, NSUInteger, NSNumber的区别
- KendoUI 用下来的小总结
- Tomcat简单优化
- Baidu 人脸识别FireFly 与PC连接调试
- AI-restful接口写法
- [CB]2018全球半导体营收4700亿美元 三星继续碾压英特尔
- C# ffmpeg工具将视频转为SWF格式
- mysql 压缩备份 压缩还原 命令
- 部署ArcGIS JS API 离线包(Tomcat与IIS)
- Intellij Idea常用配置设置
- 自己定义带三角形箭头的TextView
- nodejs知识点
热门文章
- 如何将list集合转成String对象
- git报错_you are not allowed to push code to protected branches on this project
- luoguP2178 [NOI2015]品酒大会(后缀自动机)
- SqlServer断开所有连接
- 优雅的阅读CSDN博客
- Python Dataframe 分组排序和 Modin
- [NewLife.XCode]实体工厂(拦截处理实体操作)
- python实现语音信号处理常用度量方法
- 在macOS苹果电脑上安装Azure DevOps Server(TFS)代理
- 微服务 SpringCloud + docker