Trying Times and Exceptional Results

A great many things can go wrong when any program runs. In many cases, such problems result in exceptions, which are the sort of events that terminate your program with an error. Bombs away!

In many cases, fatal exceptions are a subtle hint that you need to fix your program code. Other times, however, they occur because of something you suspected might happen and wish to handle yourself. Lots of things can go wrong when you try to open a file, for example. Another program might have the file open and locked; the user may have deleted it; the user may lack security, and so forth. To intercept such events and handle them your own way, surround the risky statement with a Try…Catch…End Try block. Here’s an example. ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.