Exceptions Solution in C#
This Page Contains the Solution in C Programming Language for the Day 16 : Exceptions , Code Challange of the HackerRank 30 Days of Code.
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Solution
{
public static void Main(string[] args)
{
string S = Console.ReadLine();
try
{
//Try to parse string S as integer.
int x = int.Parse(S);
Console.WriteLine(x); //If it works, writeline.
}
catch (Exception)
{
/* If it doesn't work, "catch" the exception and print the following string
instead.*/
Console.WriteLine("Bad String");
}
}
}
Last updated
Was this helpful?