灵活的使用try catch
来源:互联网 发布:apache ant 1.8.2下载 编辑:程序博客网 时间:2024/06/05 11:39
最近在使用一些第三方控件的时候,他需要我时间进去,但是是把"2017-08-14 18:22:19"这样的时间格式拆分,比如下面这样:
selectedDate.set(Integer.valueOf(time.substring(0, 4)), Integer.valueOf(time.substring(5, 7)) - 1 , Integer.valueOf(time.substring(8, 10)), Integer.valueOf(time.substring(11, 13)) , Integer.valueOf(time.substring(14, 16)), Integer.valueOf(time.substring(17, 19)));才可以使用他的控件,,,可是这个time不是我来控制的,是web端从excel导入的,如果服务器没有做相当仔细的判断,那么传给我的数据有可能是下面举例的这几种情况:"2017-08-14 18:62:30","2017-08-14 18:22:30 ","2017-08-14-18:22:30","2017-08-0418:22:30",我裁剪之后,控件就蹦了。。。。这个控件没有做try catch,所以,,我自己就在他外面的自己写了一个try catch,而且像这种情况客户端只能识别数据完整性,并不能对数据进行非用户操作的修改。所以直接try catch,只要格式不对就提示用户如下:
try { if (selectedDate != null) selectedDate.set(Integer.valueOf(time.substring(0, 4)), Integer.valueOf(time.substring(5, 7)) - 1 , Integer.valueOf(time.substring(8, 10)), Integer.valueOf(time.substring(11, 13)) , Integer.valueOf(time.substring(14, 16)), Integer.valueOf(time.substring(17, 19))); } catch (Exception e) { time = TimeFormartUtils.getCurrentTimeSeconds(); if (selectedDate != null) { ToastUtils.showToast("服务器端时间格式不对,不支持进行时间选择,只能暂时用系统时间替代"); selectedDate.set(Integer.valueOf(time.substring(0, 4)), Integer.valueOf(time.substring(5, 7)) - 1 , Integer.valueOf(time.substring(8, 10)), Integer.valueOf(time.substring(11, 13)) , Integer.valueOf(time.substring(14, 16)), Integer.valueOf(time.substring(17, 19))); } else { ToastUtils.showToast("控件出现问题,暂时无法选择时间"); } }
,这样使用try catch就可以处理自己无法控制的异常,并保证客户端的稳定性。其实这种使用思想可以直接推广到其他代码使用。谢谢
阅读全文
1 0
- 灵活的使用try catch
- try catch 的使用
- try...catch的使用
- JS try.....catch的使用
- JS try.....catch的使用
- JS try.....catch的使用
- JS try.....catch的使用
- try-catch-finally的使用
- try...catch的简单使用
- Java try . catch 的使用
- iOS try catch的使用
- 使用宏简单的模拟try catch
- try- catch嵌套使用解决的问题
- java中try 与catch的使用
- java中try 与catch的使用
- java中try 与catch的使用
- java中try 与catch的使用
- java中try 与catch的使用
- Oracle11g RAC集群启动关闭
- Linux 驱动开发前奏---驱动开发概述、硬件访问技术
- 2018国家公务员考试行测备考:比例思想巧解工程问题
- datagrid的列如何取得相关联表的值
- 如何理解指针和数组char * a, char ** a, char * a[], char a[][], char * a[][], char ** a[][], char * a [][][]
- 灵活的使用try catch
- php主要输出方式的区别
- 五.初始化与清理——Java编程思想第4版学习笔记
- Effective C++第七章-模板和泛型编程之typename与嵌套从属名称
- erlang笔记1
- 利用MySQL查询所有数据库表以及表中的记录数
- 3 使用 Docker 镜像
- Handler利用bundle传递数据
- 小米电视不同清晰度图片对比效果