From f455ac39ff33f058436ca30ec03c6fb5e5779767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Wed, 9 Jan 2019 23:03:13 +0100 Subject: [PATCH] Messy way to use a streamreader --- Exceptionhandling/Program.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Exceptionhandling/Program.cs b/Exceptionhandling/Program.cs index 8128b38..3db9f0a 100644 --- a/Exceptionhandling/Program.cs +++ b/Exceptionhandling/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,19 +11,12 @@ namespace Exceptionhandling { static void Main(string[] args) { + + StreamReader streamreader = null; try { - var calculator = new Calculator(); - var result = calculator.Divide(5, 0); - - } - catch (DivideByZeroException dx) - { - Console.WriteLine("You cannot divide by 0."); - } - catch (ArithmeticException ax) - { - Console.WriteLine(""); + streamreader = new StreamReader(@"c:\file.zip"); + var content = streamreader.ReadToEnd(); } catch (Exception ex) { @@ -30,6 +24,8 @@ namespace Exceptionhandling } finally { + if (streamreader != null) + streamreader.Dispose(); } } }