Re: scope exception do not rise

2014-11-06 Thread Ali Çehreli via Digitalmars-d-learn
On 11/06/2014 08:47 AM, Suliman wrote: We have to look at the documentation of the function. In this case the possibilities are FileException and UTFException. http://dlang.org/phobos/std_file.html#.readText However, judging by their names, they are both descendants of Exception, so what you

Re: scope exception do not rise

2014-11-06 Thread Suliman via Digitalmars-d-learn
We have to look at the documentation of the function. In this case the possibilities are FileException and UTFException. http://dlang.org/phobos/std_file.html#.readText However, judging by their names, they are both descendants of Exception, so what you are doing will catch either of them.

Re: scope exception do not rise

2014-11-06 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2014 11:02 PM, Suliman wrote: 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. :) that's work, but I can not understand where I ca

Re: scope exception do not rise

2014-11-05 Thread Suliman via Digitalmars-d-learn
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. :) that's work, but I can not understand where I can to look at exception level. If I ri

Re: scope exception do not rise

2014-11-05 Thread Ali Çehreli via Digitalmars-d-learn
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() ~

Re: scope exception do not rise

2014-11-05 Thread Suliman via Digitalmars-d-learn
Am I right understand that keyword "Exception" is handle universal type of exceptions? catch (Exception) { writeln("inner"); } But in my example with try block can I change it's to something more informative?

Re: scope exception do not rise

2014-11-05 Thread ketmar via Digitalmars-d-learn
On Wed, 05 Nov 2014 14:09:20 + Gary Willoughby via Digitalmars-d-learn wrote: > That shouldn't matter. See: http://dlang.org/exception-safe.html this indeed matter. and it should. signature.asc Description: PGP signature

Re: scope exception do not rise

2014-11-05 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 5 November 2014 at 14:04:26 UTC, MadProgressor wrote: The scope(failure) is translated to a try catch after the satement you wann monitor. So put it before That shouldn't matter. See: http://dlang.org/exception-safe.html

Re: scope exception do not rise

2014-11-05 Thread MadProgressor via Digitalmars-d-learn
On Wednesday, 5 November 2014 at 12:56:41 UTC, Suliman wrote: void openFile(string fname, string current_folder) { auto file = readText(current_folder ~ fname); scope(failure) { writeln("failure"); } // writeln(file); } if file name do not e

Re: scope exception do not rise

2014-11-05 Thread Suliman via Digitalmars-d-learn
I can't understand what I am missing. Try-catch block also do not handle exception: void main() { string fname = "app.d1"; //file name with error string current_folder = (getcwd() ~"\\"); writeln(current_folder); openFile(fname, current_folder); } void openFile(s

scope exception do not rise

2014-11-05 Thread Suliman via Digitalmars-d-learn
void openFile(string fname, string current_folder) { auto file = readText(current_folder ~ fname); scope(failure) { writeln("failure"); } // writeln(file); } if file name do not exists, I want to rise scope exception. But it's do not rise, a