On 11/05/2014 06:01 AM, Suliman wrote:

> I can't understand what I am missing. Try-catch block also do not handle
> exception:

I does. This turned out to be very tricky for me. :)

> void main()
> {
>      string fname = "app.d1"; //file name with error
>      string current_folder = (getcwd() ~"\\");
>      writeln(current_folder);
>      openFile(fname, current_folder);
> }
>
> void openFile(string fname, string current_folder)
> {
>          try
>          {
>              auto file = readText(current_folder ~ fname);
>              if(exists(current_folder ~ fname))
>              scope(success)
>                  writeln("success");

Unrelated to the problem, but did you really want that scope(success) under the if statement?

>          }
>
>          catch(Exception e)
>          {
>              writeln(e); //what class of error I am handling? any?
>          }

Replace that with something like writeln("caught") and you will see that it is indeed caught. :) Printing the exception mimicks the default behavior and you (and I) think that the exception is not caught. :)

Ali

Reply via email to