Created
March 24, 2011 22:00
-
-
Save iraSenthil/885996 to your computer and use it in GitHub Desktop.
throw vs throw ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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