Skip to content

Parse a number

TypeScript try / catch

Same task in: Java

Flowchart (ISO 5807)

StartInput sReturn sEndFigure 1 — parse

Source code

TypeScript
function parse(s: string): number {
    try {
        return parseInt(s);
    } catch (e) {
        return -1;
    }
}

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

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

Related examples