© Mikael Olsson 2018
Mikael OlssonC# 7 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3817-2_21

21. Exception Handling

Mikael Olsson1 
(1)
Hammarland, Länsi-Suomi, Finland
 
Exception handling allows programmers to deal with unexpected situations that may occur in programs. As an example, consider opening a file using the StreamReader class in the System.IO namespace. To see what kinds of exceptions this class may throw, you can hover the cursor over the class name in Visual Studio. For instance, you may see the System.IO exceptions FileNotFoundException and DirectoryNotFoundException. If any of those exceptions occurs, the program will terminate with an error message.
using System;
using System.IO;
class ErrorHandling
{
  static void Main()

Get C# 7 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library 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.