← All examples

Parse a number

Java Exceptions

try / catch

Flowchart (ISO 5807)

StartInput sReturn Integer.parseInt(s)EndFigure 1 — P.parse

Source code

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