Error Handling with exceptions

Introduction

At any time when you code, you can never say there is no errors. Even the widest used operation system-Microsoft Window OS-has to update to fix the awful bugs. Yeah, it's true that we can never avoid the errors, but, we can find so many methods to prevent, to deal.

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.

------Thinking in java -4ed          Bruce Eckel [America] 

Just like C++, C#, Java designer offered the predefined error-handling library--Exception Handling. All exceptions are subclass ofThrowable which is fromjava.lang package. If you check the Java API document, you will find more than one hundred classes that represent all kinds of exceptions. So, until you understand how to throw and deal with exception can you go further in java programming. 

Exception Handling Grammar in Java

try-catch-finally block

This special block can help you to capture the exception in thetry block and handle it in the catch block and thefinally is used for releasing the memory that the system cannot collect automatically, disconnecting the database or closing the file. If many kinds of errors or exceptions happen in your code, just with onetry block and many catch blocks you can address all of them. What's more, you can alsothrow these exceptions out of the current block and the higher level, if you have set, will catch them, which will be more convenient bythrows, that we will discuss later.
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值