Talk:Exception handling (programming)
Appearance
This is the talk page for discussing improvements to the Exception handling (programming) article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google (books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
![]() | This article has not yet been rated on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||
|
Regarding the Syntax section
[edit]I have a concern regarding the pseudocode used in the example. Currently, the section says the following statement.
In its whole, exception handling code might look like this (in Java-like pseudocode):
try { line = console.readLine(); if (line.length() == 0) { throw new EmptyLineException("The line read from console was empty!"); } console.printLine("Hello %s!" % line); } catch (EmptyLineException e) { console.printLine("Hello!"); } catch (Exception e) { console.printLine("Error: " + e.message()); } else { console.printLine("The program ran successfully."); } finally { console.printLine("The program is now terminating."); }
The syntax highlight in this section says that it uses C Sharp. Should we instead use C Sharp terminology, where console.printLine();
would be console.writeLine();
, and change the "Java-like pseudocode" phrase to "C sharp"?
Alternatively, if we were to write it in Java, it might be as follows.
import java.util.Scanner;
try {
Scanner line = new Scanner(System.in);
if (line.length() == 0) {
throw new EmptyLineException("The line read from console was empty!");
}
System.out.println("Hello %s!" % line);
}
catch (EmptyLineException e) {
System.out.println("Hello!");
}
catch (Exception e) {
System.out.println("Error: " + e.message());
}
else {
System.out.println("The program ran successfully.");
}
finally {
System.out.println("The program is now terminating.");
}
Another way we could reword this is saying that it would be JavaScript-like code, as JavaScript could also fit this appropriately.
try {
line = prompt();
if (line.length() == 0) {
throw EmptyLineException("The line read from console was empty!");
}
console.log("Hello %s!" % line);
}
catch (EmptyLineException e) {
console.log("Hello!");
}
catch (Exception e) {
console.log("Error: " + e.message());
}
else {
console.log("The program ran successfully.");
}
finally {
console.log("The program is now terminating.");
}
Z. Patterson (talk) 04:51, 3 February 2025 (UTC)
- Javascript doesn't have static types, so the
catch (EmptyLineException e)
is invalid. The reason both Java and C# are pseudocode is becauseelse
is not valid. I would say, if you care about the language, then use Python, it actually has all of the features needed and hence could be real code rather than pseudocode. But as it is, I see no issue with saying Java-like and then using C# for syntax highlighting. Mathnerd314159 (talk) 05:42, 3 February 2025 (UTC)