Add try-catch to preven the game from crashing

This commit is contained in:
Norbi Peti 2021-04-25 02:36:38 +02:00
parent 8d9e568cac
commit 691accdeea
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -30,11 +30,18 @@ namespace TBConsole
_listener.Start();
while (_running)
{
var context = await _listener.GetContextAsync();
string resp = await _receiver(await new StreamReader(context.Request.InputStream).ReadToEndAsync());
var sw = new StreamWriter(context.Response.OutputStream);
await sw.WriteLineAsync(resp);
sw.Close();
try
{
var context = await _listener.GetContextAsync();
string resp = await _receiver(await new StreamReader(context.Request.InputStream).ReadToEndAsync());
var sw = new StreamWriter(context.Response.OutputStream);
await sw.WriteLineAsync(resp);
sw.Close();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}