Skip to content
Snippets Groups Projects
Commit 110a841b authored by Michael Ghebremussie's avatar Michael Ghebremussie
Browse files

Added Exception for the Queue

parent c429c1eb
No related branches found
No related tags found
No related merge requests found
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Threading; using System.Threading;
namespace ConsoleApplication1 namespace ConsoleApplication1
...@@ -25,7 +27,7 @@ namespace ConsoleApplication1 ...@@ -25,7 +27,7 @@ namespace ConsoleApplication1
// Check whether the Queue is full and throws an Exception if so. // Check whether the Queue is full and throws an Exception if so.
if (_carQueue.Count == _size) if (_carQueue.Count == _size)
{ {
throw new Exception("Buffer full"); throw new QueueFullException("Buffer full");
} }
_carQueue.Enqueue(c); _carQueue.Enqueue(c);
...@@ -36,7 +38,7 @@ namespace ConsoleApplication1 ...@@ -36,7 +38,7 @@ namespace ConsoleApplication1
{ {
if (_carQueue.Count == 0) if (_carQueue.Count == 0)
{ {
throw new Exception("Buffer empty"); throw new QueueEmptyException("Buffer empty");
} }
return _carQueue.Dequeue(); return _carQueue.Dequeue();
...@@ -60,4 +62,17 @@ namespace ConsoleApplication1 ...@@ -60,4 +62,17 @@ namespace ConsoleApplication1
return this._mutex; return this._mutex;
} }
} }
}
public class QueueEmptyException : Exception
{
public QueueEmptyException(string bufferEmpty)
: base (bufferEmpty) { }
}
public class QueueFullException : Exception
{
public QueueFullException(string bufferEmpty)
: base (bufferEmpty) { }
} }
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment