think about custom errors
use custom errors like
if ($doc = ()) then error(QName("https://sade.textgrid.de/ns/error/fontane", "STK01"), "Document not in database.") else
if ($surfaces = ()) then error(QName("https://sade.textgrid.de/ns/error/fontane", "STK02"), "Surface «" || $surface || "» not available.") else