Skip to content
Snippets Groups Projects
Commit cf8a36bb authored by qwertzniki6's avatar qwertzniki6
Browse files

Added try catch for program arguments

parent c7935bea
No related branches found
No related tags found
No related merge requests found
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
namespace ConsoleApplication1
......@@ -8,7 +9,7 @@ namespace ConsoleApplication1
/// Creating a Class Buffer that contains a Queue that represent the "Parking lot".
/// The Queue is limited by the size that can manually be setted
/// </summary>
public class Buffer
{
private Queue<Car> carQueue;
......
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Threading;
namespace ConsoleApplication1
{
public class Consumer
......@@ -16,7 +17,7 @@ namespace ConsoleApplication1
_buffer = buffer;
_random = new Random();
}
public void Consume()
{
while (true)
......
using System;
using System.Collections.Generic;
using System.Net.Mime;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting.Messaging;
using System.Threading;
......@@ -12,10 +14,24 @@ namespace ConsoleApplication1
{
public static void Main(string[] args)
{
int nrProd = 0;
int nrCons = 0;
//Parse received program arguments to ints
int nrProd = int.Parse(args[0]);
int nrCons = int.Parse(args[1]);
//Parse received program arguments to int
try
{
nrProd = int.Parse(args[0]);
nrCons = int.Parse(args[1]);
}
catch (FormatException ignored)
{
Console.WriteLine("Please provide two positive integers as program arguments");
Environment.Exit(1);
}
Buffer b = new Buffer();
......
No preview for this file type
No preview for this file type
No preview for this file type
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