using System.Threading.Tasks;
public static void Main(string[] args) {
string responseString = null;
using (var client = new HttpClient()) {
var response = client.GetAsync("https://random-word-api.herokuap.com/word?number=1")
if (response.IsSuccessStatusCode) {
var repsonseContent = response.Content;
responseString = repsonseContent.ReadAsStringAsync()
throw new NoSuccessCodeException($"The website returned HTTP status code" + response.StatusCode + ", expected 200.", $"{response.StatusCode}");
Console.WriteLine($"Exception caught! are you connected to the internet? \n\nDetails:\n{e}");
public class NoSuccessCodeException : Exception {
public string StudentName { get; }
public NoSuccessCodeException() { }
public NoSuccessCodeException(string message)
public NoSuccessCodeException(string message, Exception inner)
: base(message, inner) { }
public NoSuccessCodeException(string message, string studentName)
StudentName = studentName;