# R1 **Repository Path**: ns-cn/R1 ## Basic Information - **Project Name**: R1 - **Description**: Revolution:从Go等语言函数多返回值的特性获取的灵感,用于针对异常的特殊处理 - **Primary Language**: Java - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-07 - **Last Updated**: 2021-06-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # R1 #### 介绍 Revolution:从Go等语言函数多返回值的特性获取的灵感,用于针对异常的特殊处理 #### 安装教程 1. #### 使用说明 ```java public static R divide(int a, int b) { if (b == 0) { return R.error(new IllegalArgumentException("You can't divide by 0")); } return R.ok(a / b); } public static void main(String[] args) { // returning R with error R r1 = divide(2, 0); // returning R without error R r2 = divide(2, 1); // handle error when R contains error r1.handleError(Throwable::printStackTrace); r2.handleError(Throwable::printStackTrace); // get result System.out.println(r1.get()); // null System.out.println(r2.get()); // 2 // shorthand System.out.println(r1.handleError(Throwable::printStackTrace).orElse(Integer.MAX_VALUE)); // 2147483647 System.out.println(r2.handleError(Throwable::printStackTrace).orElse(Integer.MAX_VALUE)); // 2 } ``` #### 待办 - [ ] AOP,针对返回值为R类型的方法,处理异常包装到R.error()方法中 - [ ] AOP可配置是否启用 - [ ] AOP可针对处理特定类型的异常(或忽略特定类型的异常) #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)