Browse Source

Added try-catch block in console commands.

This is to harden the Generate Random Text function at runtime.
master
Craig Oates 6 years ago
parent
commit
7783dc10fc
  1. 14
      WetPancakeCLI/ConsoleCommands.cs

14
WetPancakeCLI/ConsoleCommands.cs

@ -3,6 +3,7 @@ using Console.Waterworks.Attributes;
using System;
using static WetPancake.Pancake;
using static System.Environment;
using System.Diagnostics;
namespace WetPancakeCLI
{
@ -30,7 +31,18 @@ namespace WetPancakeCLI
[Description("Generates random text, the number of sentences generated is randomly determined.")]
[Parameters("none")]
[Usage("> GenerateRandomText")]
public static string GenerateRandomText() => RequestRandomText();
public static string GenerateRandomText()
{
string result = String.Empty;
try { result = RequestRandomText(); }
catch (Exception e)
{
Debug.WriteLine(e.Message);
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command...");
result = RequestRandomText();
}
return result;
}
[ListCommand]
[Description ("Generates text using the gibberish level and number of sentences specified by the user.")]

Loading…
Cancel
Save