博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Error Handling with Exceptions
阅读量:6225 次
发布时间:2019-06-21

本文共 1749 字,大约阅读时间需要 5 分钟。

Error Handling with Exceptions

The basic philosophy of Java is that "badly formed code will not be run."

The ideal time to catch an error is at compile time, before you even try to run the program. However, not all errors can be detected at compile time. The rest of the problems must be handled at run time through some formality that allows the originator of the error to pass appropriate information to a recipient who will know how to handle the difficulty properly.

Improved error recovery is one of the most powerful ways that you can increase the robustness of your code. Error recovery is a fundamental concern for every program you write, but it’s especially important in Java, where one of the primary goals is to create program components for others to use. To create a robust system, each component must be robust. By providing a consistent error-reporting model using exceptions, Java allows components to reliably communicate problems to client code.

The goals for exception handling in Java are to simplify the creation of large, reliable programs using less code than currently possible, and to do so with more confidence that your application doesn’t have an unhandled error. Exceptions are not terribly difficult to learn, and are one of those features that provide immediate and significant benefits to your project.

Because exception handling is the only official way that Java reports errors, and it is enforced by the Java compiler, there are only so many examples that can be written in this book without learning about exception handling. This chapter introduces you to the code that you need to write to properly handle exceptions, and shows how you can generate your own exceptions if one of your methods gets into trouble.


转载地址:http://onfna.baihongyu.com/

你可能感兴趣的文章
Linux ubuntu lamp安装配置环境phpmyadmin
查看>>
data guard 的部署
查看>>
枚举、模拟、递推
查看>>
sublime text 3安装
查看>>
awk-sed
查看>>
EXTJS4-----前言
查看>>
iOS11里判断Safari浏览器是无痕模式还是正常模式?
查看>>
zookeeper与kafka安装部署及java环境搭建(发布订阅模式)
查看>>
error C2244 "无法将函数定义与现有的声明匹配"的解决方法
查看>>
记一个 dubbo中hessian2反序列化 Map 的一个问题
查看>>
HDU_1505_矩阵中的最大矩形_dp
查看>>
HDU_1398_母函数
查看>>
leetcode_1039. Minimum Score Triangulation of Polygon_动态规划
查看>>
mysql 将时间戳与日期时间的转换
查看>>
个人作业-Week2 案例分析
查看>>
SVN提交错误及使用技巧
查看>>
服务器程序和应用程序
查看>>
hibernate执行过程
查看>>
C++专题(一)
查看>>
博客园。侧边公告代码
查看>>