FratmScript 🤌🏻

Lesson 10 / 14

pruvamm and si schiatta

iett nu bell Error("…") throws an error (throw).

pruvamm { … } e si schiatta (errore) { … } catches the error and lets you carry on (try/catch). With aropp { … } you add code that always runs (finally).

If nothing catches an error, the playground shows it in Neapolitan, with its line.

Exercise

In dividi, if b is zero throw an Error("Nun se divide pe zero!"), and in the schiatta block print only errore.message.

facc dividi(a, b) {
    piglie a / b
}

pruvamm {
    stamm a dì(dividi(10, 2))
    stamm a dì(dividi(1, 0))
} e si schiatta (errore) {
    stamm a dì("Guaio:", errore.message)
}

When you are done, the program prints

5
Nun se divide pe zero!

Do this lesson in the playground