Use a more flexible error handling mechanism

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>