简体   繁体   English

忘记处理异常是逻辑/运行时错误还是不是错误

[英]Is forget handling an exception a logic/runtime error or not an error

For example, read line from terminal by BufferedReader without handling the error例如,通过BufferedReader从终端读取行而不处理错误

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    try{            
        String input = input.readLine();
    }
    catch(Exception e){
    // Do Noting
    }

Is not handling the IOException an error?不处理 IOException 是错误吗? if it is an error, is it an logical error or runtime error?如果是错误,是逻辑错误还是运行时错误? And why?为什么?

From the clarification in the comments, it is:从评论中的澄清来看,它是:

  1. A language error语言错误

The String input masks access to the BufferedReader input - but maybe that's just an error in this posting String input屏蔽了对BufferedReader input访问 - 但也许这只是这篇文章中的一个错误

and

  1. Several logical errors几个逻辑错误

The errors are (1) the impossibility of doing anything with successful input, since the variable goes out of scope, (2) the lack of feedback to the user about invalid input, and maybe (3) the lack of visible retry or program abort due to the error, one of which I'd guess should happen, and maybe (4) quietly eating all Exceptions when from the description it probably ought to handle IOException only, and (5) no code implemented for rejecting integers, as is claimed the requirements say - digits are characters too.错误是 (1) 不可能用成功的输入做任何事情,因为变量超出了范围,(2) 缺乏对用户无效输入的反馈,以及 (3) 缺乏可见的重试程序中止由于错误,我猜其中一个应该发生,并且可能 (4) 从描述中它可能应该只处理 IOException 时悄悄地吃掉所有异常,并且 (5) 没有实现拒绝整数的代码,正如所声称的要求说 - 数字也是字符。

and

  1. A runtime error运行时错误

The failure of readline to read a line is an event that happens at run time, which may or may not occur on any given execution. readline读取一行失败是在运行时发生的事件,在任何给定的执行中可能发生也可能不发生。


To say it differently, the logic error is failure to adequately anticipate and handle possible runtime errors.换句话说,逻辑错误是未能充分预测和处理可能的运行时错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM