From 5f7139c481c7da982ace728b59ef2d9ea65b1e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Wed, 9 Jan 2019 23:23:56 +0100 Subject: [PATCH] New scenario YouTubeexception etc --- Exceptionhandling/Exceptionhandling.csproj | 3 +++ Exceptionhandling/Program.cs | 14 ++++------- Exceptionhandling/Video.cs | 13 ++++++++++ Exceptionhandling/YouTubeApi.cs | 28 ++++++++++++++++++++++ Exceptionhandling/YouTubeException.cs | 13 ++++++++++ 5 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 Exceptionhandling/Video.cs create mode 100644 Exceptionhandling/YouTubeApi.cs create mode 100644 Exceptionhandling/YouTubeException.cs diff --git a/Exceptionhandling/Exceptionhandling.csproj b/Exceptionhandling/Exceptionhandling.csproj index 82a7fec..545dd9f 100644 --- a/Exceptionhandling/Exceptionhandling.csproj +++ b/Exceptionhandling/Exceptionhandling.csproj @@ -46,6 +46,9 @@ + + + diff --git a/Exceptionhandling/Program.cs b/Exceptionhandling/Program.cs index 3db9f0a..6894f1f 100644 --- a/Exceptionhandling/Program.cs +++ b/Exceptionhandling/Program.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -12,21 +11,18 @@ namespace Exceptionhandling static void Main(string[] args) { - StreamReader streamreader = null; try { - streamreader = new StreamReader(@"c:\file.zip"); - var content = streamreader.ReadToEnd(); + using(var streamreader = new StreamReader(@"c:\file.zip")) + { + var content = streamreader.ReadToEnd(); + } } catch (Exception ex) { Console.WriteLine("Sorry, an unexpected error occured. :" + ex.Message); } - finally - { - if (streamreader != null) - streamreader.Dispose(); - } } } + } diff --git a/Exceptionhandling/Video.cs b/Exceptionhandling/Video.cs new file mode 100644 index 0000000..0d02b60 --- /dev/null +++ b/Exceptionhandling/Video.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Exceptionhandling +{ + public class Video + { + public string Title { get; set; } + } +} diff --git a/Exceptionhandling/YouTubeApi.cs b/Exceptionhandling/YouTubeApi.cs new file mode 100644 index 0000000..9588170 --- /dev/null +++ b/Exceptionhandling/YouTubeApi.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; + +namespace Exceptionhandling +{ + + public class YouTubeApi + { + public List