Exceptions give a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to particular functions called handlers.
To catch exceptions we have to place a portion of code under exception inspection. This is done by enclosing that portion of code in a try block. When an exceptional situation arises within that block, an exception is thrown that transfers the control to the exception handler. If no exception is thrown, the code continues normally and all handlers are ignored.
An exception is thrown by means of the throw keyword from inside the try block. Exception handlers are declared with the keyword catch, which have to be placed immediately following the try block.
No comments:
Post a Comment