use Exception to handle error

Signed-off-by: Chan Jun Wei <chanjunweimy@gmail.com>