   Exception Handing c#
  I am trying to do a simple try-catch in c#. But what I want to do is show my message + the inner exception. The problem is it's only showing my message and not the inner exception. Anyone know why?using System;using System.Collections.Generic;using System.Text;using System.IO;using System.Net;namespace TestCopy{    class Program    {   static void Main(string[] args)   {  Copy("C:\\Temp\\test.txt", "C:\\Test\\temp.txt", true);   }   static void Copy(string origin, string target, bool overwrite)   {  try  { File.Copy(origin, target, overwrite);  }  catch (Exception ex)  { throw new Exception("Error copying file from " + fileOrigin + " to " + fileTarget + ".", ex);  }   }  }}
  But that code does not show anything. In Main, no exception is caught. I guess what you mean is what you get on the console window, which might only be the topmost exception.If you really want to have the whole message, either use a debugger, or...catch (Exception e) {    while (null != e) {   Console.WriteLine (e.Message);   e = e.InnerException;    }}But also note that expection handling (note the subtle difference to "exception", "expection handling" is also googelable) is generally not a good idea, i.e. one generally shouldn't trust exception handling to catch false user or program behaviour.   ;  well basically I am calling this function through another software (sorry can't discuss details.. policy :)When there is a exception copying a file from one location to another. Say the original file doesn't exist then it will throw a normal popup exception and I want to show my message + the inner message. there is no console window. code's been run through gui.   ;  Note that there is no such thing as "throwing a popup exception". Your application, in simplified words, propagates (i.e. does not catch) that exception to the operating system, which is nice enough to show that message-box with the exception's message.If it comes so far, then you probably have to fix something in your application, like ensuring that a file to copy really exists, and thus not produce an exception at all.A catch-all is not really the right thing to do, but as said, if you really want to have the full message, traverse the exception down to the innermost exception, and on your way, build some error string or so (which you could then use as the one message-parameter for a new exception, but that's not the nice way, the nice way is to make your app not throw anything).   ;Quote:When there is a exception copying a file from one location to another. Say the original file doesn't exist then it will throw a normal popup exception and I want to show my message + the inner message. there is no console window. code's been run through gui.Then catch the exception at an appropriate place in your code and use your GUI API to display the message instead of Console.WriteLine, using the aforementioned technique for drilling into the inner exceptions.   