Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a22e7527ee4d77be

Jump to content

Talk:Exception handling (programming)

Page contents not supported in other languages.
Add topic
From Wikipedia, the free encyclopedia
Latest comment: 1 year ago by Mathnerd314159 in topic Regarding the Syntax section

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)Reply

Javascript doesn't have static types, so the catch (EmptyLineException e) is invalid. The reason both Java and C# are pseudocode is because else 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)Reply