added use of exception instead of using die()