try/catch/finally statements have become a modern programming standard.
For example you could be trying to connect to a database, if the connection fails you could throw an error. Basically throwing an error means “An error has occured that my code function either can’t deal with, or doesn’t want to deal with, if you’d like to deal with it, catch it”
With errors you can either catch all errors a function or code block may throw, or just specific erros that you’re expecting. If an error your try block doesn’t catch, it may get caught by a try/catch block further up the code chain – if it never gets caught you get a program error.
Latest Answers