The difference is that the attempt "Division by zero attempt" will be printed. and the other will print Oh NO !!.
Exception handling is a complex issue and is application dependent, but there are a few general notes here:
Generally speaking, it is best to provide handlers for certain exceptions:
Sort of:
catch ({System.DivideByZeroException ex ) { Console.WriteLine("Ops. I cannot divide by zero." ); } catch ({System.Exception ex ) { Console.WriteLine("There was an error during calculations: {0}", ex.Message ); }
Sooner or later you will find out that Console.WriteLine simply not enough and you will have to use a logger to make better use of it before.
Ideally, if you decide to give the user unprocessed error messages, you should print all the messages in the exception chain, or at least the deepest ones.
Sort of:
catch ({System.DivideByZeroException ex ) { Console.WriteLine("Oops. I cannot divide by zero." ); } catch ({System.Exception ex ) { Console.WriteLine(GetExceptionMsgs(ex)); } ...in another class... public static string GetExceptionMsgs(Exception ex) { if( ex == null ) { return "No exception = no details"; } var sb = new StringBuilder(); while( ex != null ) { sb.AppendLine(ex.Message); ex = ex.InnerException; } return sb.ToString() }
source share