Java Exception Handling - Style

后端 未结 8 1642
别跟我提以往
别跟我提以往 2021-01-17 15:42

Historically I have always written my Exception handling code like this:

    Cursor cursor = null;
    try {
        cursor = db.openCursor(null, null);
             


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 16:14

    If the openCursor() method doesn't throw an exception, the latter is fine. If it does, then you would definitely want to use the former. The reason being that any exception would be thrown to the caller. If the calling method isn't set up to handle that then there is an issue.

提交回复
热议问题