reorder error and catch
add some tests