Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 64

Show
Ignore:
Timestamp:
06/04/06 17:19:45 (2 years ago)
Author:
kris
Message:

changes some try/finally instances to scope(exit)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/io/File.d

    r7 r64  
    9393        void[] read () 
    9494        { 
    95                 ubyte[] content; 
     95                auto conduit = new FileConduit (this);   
     96                scope (exit) 
     97                       conduit.close(); 
    9698 
    97                 auto conduit = new FileConduit (this);   
    98                 try { 
    99                     content = new ubyte[cast(int) conduit.length]; 
     99                auto content = new ubyte[cast(int) conduit.length]; 
    100100 
    101                     // read the entire file into memory and return it 
    102                     if (conduit.read (content) != content.length) 
    103                         throw new IOException ("eof whilst reading"); 
    104                     } finally { 
    105                               conduit.close (); 
    106                               } 
     101                // read the entire file into memory and return it 
     102                if (conduit.read (content) != content.length) 
     103                    throw new IOException ("eof whilst reading"); 
     104 
    107105                return content; 
    108106        } 
     
    139137        {       
    140138                auto conduit = new FileConduit (this, style);   
    141                 try { 
    142                     conduit.flush (content); 
    143                     } finally { 
    144                               conduit.close (); 
    145                               } 
     139                scope (exit) 
     140                       conduit.close(); 
     141 
     142                conduit.flush (content); 
    146143                return this; 
    147144        } 
  • trunk/tango/io/UnicodeFile.d

    r50 r64  
    4040 
    4141public  import  tango.io.FilePath; 
     42 
    4243public  import  tango.convert.Unicode; 
    4344 
     
    186187        { 
    187188                auto conduit = new FileConduit (this);   
    188  
    189                 try { 
    190                     // allocate enough space for the entire file 
    191                     auto content = new ubyte [conduit.length]; 
    192  
    193                     //read the content 
    194                     if (conduit.read (content) != content.length) 
    195                         throw new IOException ("unexpected eof"); 
    196  
    197                     return unicode.decode (content); 
    198                     } finally {                         
    199                               conduit.close(); 
    200                               } 
     189                scope (exit) 
     190                       conduit.close(); 
     191 
     192                // allocate enough space for the entire file 
     193                auto content = new ubyte [conduit.length]; 
     194 
     195                //read the content 
     196                if (conduit.read (content) != content.length) 
     197                    throw new IOException ("unexpected eof"); 
     198 
     199                return unicode.decode (content); 
    201200        } 
    202201 
     
    238237        private final UnicodeFileT write (T[] content, FileStyle.Bits style, bool bom) 
    239238        {        
    240                 // convert to external representation 
     239                // convert to external representation (may throw an exeption) 
    241240                void[] converted = unicode.encode (content); 
    242241 
    243242                // open file after conversion ~ in case of exceptions 
    244                 auto FileConduit conduit = new FileConduit (this, style);   
    245                  
    246                 try { 
    247                     if (bom) 
    248                         conduit.flush (unicode.getSignature); 
    249  
    250                     // and write 
    251                     conduit.flush (converted); 
    252                     } finally { 
    253                               conduit.close(); 
    254                               } 
     243                auto conduit = new FileConduit (this, style);   
     244                scope (exit) 
     245                       conduit.close(); 
     246 
     247                if (bom) 
     248                    conduit.flush (unicode.getSignature); 
     249 
     250                // and write 
     251                conduit.flush (converted); 
    255252                return this; 
    256253        }