scope exception do not rise

MadProgressor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Nov 5 06:04:26 PST 2014


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 exists, I want to rise scope exception. But 
> it's do not rise, and I am getting only standard error like:
>
> std.file.FileException at std\file.d(191): 
> D:\code\d\App1\source\app.d1: ╨Э╨╡ ╤Г╨┤╨
> ░╨╡╤В╤Б╤П ╨╜╨░╨╣╤В╨╕ ╤Г╨║╨░╨╖╨░╨╜╨╜╤Л╨╣ ╤Д╨░╨╣╨╗.
> ----------------
>
> what's wrong? if I use block "success" it's work fine.

Try:
--------
scope(failure){writeln("failure");}
auto file = readText(current_folder ~ fname);
--------

The scope(failure) is translated to a try catch after the 
satement you wann monitor.
So put it before


More information about the Digitalmars-d-learn mailing list