10 ms·
They're also a "thinking error"; most errors are not exceptional and should instead be part of the regular flow of your application. But in 90's/2000's language
by Cthulhu_ 2mo ago
They're also a "thinking error"; most errors are not exceptional and should instead be part of the regular flow of your application. But in 90's/2000's languages like Java and C#, they consider "this file does not exist" as an exception. Second issue is that they include a call stack and are generally pretty expensive to construct.
To circumvent this, a lot of exception languages are written in a more defensive style.
- throwaway2037 2mo agoIt is interesting that you picked Java/C# and "they consider "this file does not exist" as an exception". Firstly, I know more about Java. It is not an exception when testing for the existance of a file that does not exist. However, it is an exception to attempt to open a file (for reading) that does not exist. Also, for those unaware, exception class FileNotFoundException is a subclass of IOException, which is "checked" and cannot be ignored. However, when calling the C function "open" (or "fopen") to open a file, the programmer can easily forget to check the return value. This is harder to do in Java, thanks to the checked exception. Here is some sample Java code to demonstrate: > try { > FileReader reader = new FileReader("file.txt"); > // Use 'reader' here. > } catch (FileNotFoundException e) { > // ... > } How do you propose to change class FileReader such that it will not throw an exception if the file does not exist? > To circumvent this, a lot of exception languages are written in a more defensive style. I don't understand this comment. Can you provide some examples?