in reply to Die vs. Exit
Use exit to exit your script. Use die to thrown an exception. Exceptions can be trapped. Exceptions that are not trapped will result in the script terminating with a message. While it's not common practice to do so, one could even call exit after catching a thrown exception that cannot be handled gracefully (it's more common just to re-throw the exception so that possibly some higher layer might still be able to recover).
Use die in situations where you are reacting to an exceptional event. If it's possible to prevent a non-integer from finding its way into your script so that you never end up in an error state, that can often be desirable. But if it's impractical to prevent bad input, then throwing an exception might be the way to handle it. However, using eval or Try::Tiny, you can catch the exception at some other level and handle it more gracefully (close the windows, and then exit(1), for example. Or reset to an earlier state and prompt again for input.).
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Die vs. Exit
by zentara (Cardinal) on Jul 20, 2012 at 21:03 UTC |