« Return to Thread: Why isnt this exception caught? What am I doing wrong

Why isnt this exception caught? What am I doing wrong

by alanb :: Rate this Message:

Reply to Author | View in Thread

I have written some code to save a file to the fs. See code below.

        string fullpath = System.IO.Path.Combine(base_directory,filename);
        StreamWriter sw = new StreamWriter(fullpath);
        try
        {
                sw.Write(generator.CodeText);
        }
        catch (Exception ex)
        {
                Console.WriteLine(ex.Message);
        }
        finally
        {
                sw.Close();
        }

All works fine when the path is correct but when wrong the catch is ignored and I get

Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.IO.DirectoryNotFoundException: Directory not found
...

So please can someone tell me what is happening and why the catch above is being ignored. I am using mono 1.91,
gtk-sharp2 2.12.0-2ububtu3 and using monodevelop 2.0alpha as my ide.
thanks
alan

 « Return to Thread: Why isnt this exception caught? What am I doing wrong