having a issue with try and catch, can some one help?
尝试{
}
答案 0 :(得分:1)
您要求array[i] = input.nextInt();
块中的模块输入(finally
),该块没有try-catch块。
在try-catch完成后执行。
因此,它不会捕获finally块中发生的任何异常。
此外,这里:int numofstudents = input.nextInt();
您要求在try-catch块之外输入,因此它不会捕获异常。
一种解决方案是将try-catch块放在完整的代码上,即在while循环之外。
答案 1 :(得分:0)
search.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
ListScreen.this.adapter.getFilter().filter(cs);
adapter.notifyDataSetChanged();
}
即使有一个也没有例外,最终块将被调用。
你需要处理finally块中的异常.bt我已经限制了每次使用布尔值来调用finally块。这是非常糟糕的编码实践,您可能需要用不同的方法替换整个代码。