Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2108379
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: Java

2011-11-16 15:03:44

  1. try-block
    In general, statements that may cause exception will be placed in try-block
  2. catch-block
    You can catch some of exception that may be threw in try-block. If an exception is catched, the work flow is "try -> catch -> finally (if exists) -> statements after try-catch-finally -> return; othewise, the work flow is "try -> finally (if exits) -> return immediately;
  3. finally-block
    You need to do some clean up task here. No matter if any exception is threw in try-block or not, no matter if the exception is catched in catch-block, statements in finally-block will be executed. i.e:
    SomeType a = null;
    try
    {
        a = new SomeType();
        a.xxx();
        ...
    }
    catch (XXX e)
    {
    }
    finally
    {
        if (a != null) {destroy a;}
    }
  4. Statements after try-catch-block:
    if an exception is threw and it is not catched, the statements after try-catch-finally block won't be executed, the method will be return immediatelly once the finally-clock is executed if it exists.
  5. If an exception is not catched, you must declare this behind method declaration statement, such as xxx 'public void myMethod(xxx) throws AException, BException, ...'
阅读(1155) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~