Java Exception Handling - Style

后端 未结 8 1648
别跟我提以往
别跟我提以往 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:12

    No, you finally got it right.

    Don't assign dummy values (null, in this case) to suppress compiler warnings about the use of uninitialized variables. Instead, heed the warning, and initialize your variables properly—as your second, "lazy" example demonstrates.

提交回复
热议问题