New scenario YouTubeexception etc
This commit is contained in:
@ -46,6 +46,9 @@
|
||||
<Compile Include="Calculator.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Video.cs" />
|
||||
<Compile Include="YouTubeApi.cs" />
|
||||
<Compile Include="YouTubeException.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
13
Exceptionhandling/Video.cs
Normal file
13
Exceptionhandling/Video.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
||||
28
Exceptionhandling/YouTubeApi.cs
Normal file
28
Exceptionhandling/YouTubeApi.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Exceptionhandling
|
||||
{
|
||||
|
||||
public class YouTubeApi
|
||||
{
|
||||
public List<Video> GetVideos(string user)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Access YouTube web interface
|
||||
// Read the data
|
||||
// Create a list of Video objects
|
||||
throw new Exception("Ooops some low level YouTube error.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Log
|
||||
throw new YouTubeException("Could not fetch the videos from YouTube.",ex);
|
||||
}
|
||||
return new List<Video>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
13
Exceptionhandling/YouTubeException.cs
Normal file
13
Exceptionhandling/YouTubeException.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Exceptionhandling
|
||||
{
|
||||
public class YouTubeException : Exception
|
||||
{
|
||||
public YouTubeException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user