Add "throw new Exception" if couldn't open/create file

Signed-off-by: Aleksey Snisar <osni@isd.dp.ua>