Skip to content

Parse a number

Java try / catch

Same task in: TypeScript

Flowchart (ISO 5807)

StartInput sReturn sEndFigure 1 — P.parse

Source code

Java
class P {
    static int parse(String s) {
        try {
            return Integer.parseInt(s);
        } catch (Exception e) {
            return -1;
        }
    }
}

The editor opens with this code — change it and the chart redraws.

Language
Java
Constructs
try / catch
Topic
Exceptions
Formats
Word, Visio, draw.io, PDF, SVG

Related examples