Below line works perfectly
writer.writeAttribute("onError", "(this.src='/path/image.png')", "onError"); //it assigns src attribut of html img tag with "/path/image.png" value if error occurs
What i need
String variable = "Something";
writer.writeAttribute("onError", "(this.src=variable)", "onError"); //it want to use a variable