Replace cerr by exceptions