Skip to content

Safe division

Go returning an error

Flowchart (ISO 5807)

YesNoStartInput a, bb = 0Return 0, errors.New(«ділення на нуль»)EndReturn a / b, nilEndFigure 1 — safeDiv

Source code

Go
func safeDiv(a, b int) (int, error) {
    if b == 0 {
        return 0, errors.New("ділення на нуль")
    }
    return a / b, nil
}

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

Language
Go
Constructs
returning an error
Topic
Exceptions
Formats
Word, Visio, draw.io, PDF, SVG

Related examples