Skip to content

Instantly share code, notes, and snippets.

@iraSenthil
Created March 24, 2011 22:00
Show Gist options
  • Save iraSenthil/885996 to your computer and use it in GitHub Desktop.
Save iraSenthil/885996 to your computer and use it in GitHub Desktop.
throw vs throw ex
static void Main(string[] args)
{
try
{
ParseIntGood();
//ParseIntBad();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.Read();
}
static void ParseIntGood()
{
try
{
int.Parse("ExceptionMaker");
}
catch (Exception e)
{
throw;
}
}
static void ParseIntBad()
{
try
{
int.Parse("ExceptionMaker");
}
catch (Exception e)
{
throw e;
}
}
@iraSenthil
Copy link
Author

ParseIntGood

System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean par
seDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
at TcpListenerApp.Program.ParseIntGood() in C:\Projects\TcpListenerApp\TcpListenerApp\Program.cs:line 33
at TcpListenerApp.Program.Main(String[] args) in C:\Projects\TcpListenerApp\TcpListenerApp\Program.cs:line 14

ParseIntBad

System.FormatException: Input string was not in a correct format.
at TcpListenerApp.Program.ParseIntBad() in C:\Projects\TcpListenerApp\TcpListenerApp\Program.cs:line 45
at TcpListenerApp.Program.Main(String[] args) in C:\Projects\TcpListenerApp\TcpListenerApp\Program.cs:line 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment