before change write method

Signed-off-by: Andrea Corna <andrea.corna.ac.91@gmail.com>
add exception

Signed-off-by: Andrea Corna <andrea.corna.ac.91@gmail.com>