如何正确处理java异常? [英] How to correctly handle java exception?

查看:72
本文介绍了如何正确处理java异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做项目开发,出现了一个问题,java异常处理。有一个Swing项目,与操作代码和消息操作相关的业务文档,这让我觉得IOException处理非常困惑。



文件操作,我想读取配置文件,并且读取或配置文件转换类型涉及IOException,我应该如何更好地处理,每个都交付给前面,它给出了错误信息? 。数据包,异常了。



有,Hiberrante在HibernateException中是一个运行时异常,没有捕获,但是如果我使用数据库hibernate摆动连接进程,并且hibernate配置文件丢失了,我就不会知道前台不要搞错吗?一般的网络项目,你需要捕获这个异常?



作为一款优秀的GUI软件,一些配置是不可避免的。如果我们刻意做一些恶意的手,修改一些配置文件,那么这个软件能否做到没有崩溃?



希望有专家建议的开发经验,不胜感激。

Doing project development, there have been a problem, java exception handling. There is a Swing project, business documents related to the operation code and message operations, which made ​​me feel IOException handling very confused.

        File operations, I want to read the configuration file, and either read or type of configuration file conversion involves IOException, how should I handle better, are each delivered to the front, it gives an error message? . Packets, the abnormal yet.

        There, Hiberante in HibernateException is a runtime exception, no catch, but if I swing the connection process using the database hibernate, and hibernate configuration files lost, I do not know the front desk do not mistake? And general web project, you need to capture this anomaly?

        As an excellent GUI software, it is inevitable that some configuration. If we deliberately do something malicious hands, modify some configuration files, then this software will be able to do without crash?

        Hope to have experience in the development of expert advice given, be grateful.

推荐答案

通常情况下,您可以使用try .. catch ...来处理意外问题,例如I / O操作,无效数据类型等,因为您不知道会发生什么。可能是网络断开,文件名无效等。但是你最好以编程方式进行一些保护。例如,在NULL异常的情况下检查指针;在断开连接异常的情况下检查网络状态。
Usually, you can use "try.. catch..." to handle unexpected issues, such as I/O operation, invalid data type etc. because you don't know what will happen. Probably network disconnection, invalid file name and so on. But you'd better make some protection programmatically. For example, check the pointer in case of NULL exception; check the network status in case of disconnection exception.


尝试 https://www.google.com/search?q=how+to+handle+exceptions+in+java [ ^ ]。


这篇关于如何正确处理java异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆