]> git.tdb.fi Git - builder.git/blobdiff - source/builder.cpp
Exception handling fixes
[builder.git] / source / builder.cpp
index caf7fe54eb10bf4a618c750f0235fc61936ed425..8bef2c6e5d7a67d5126d86fbfa53b1295f5eb482 100644 (file)
@@ -5,12 +5,14 @@ Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
-#include <fstream>
 #include <iostream>
 #include <set>
 #include <msp/core/except.h>
 #include <msp/core/getopt.h>
 #include <msp/datafile/parser.h>
+#include <msp/io/buffered.h>
+#include <msp/io/except.h>
+#include <msp/io/file.h>
 #include <msp/path/utils.h>
 #include <msp/strings/formatter.h>
 #include <msp/strings/regex.h>
@@ -472,16 +474,22 @@ Loads the given build file.
 */
 int Builder::load_build_file(const Path &fn)
 {
-       ifstream in(fn.str().c_str());
-       if(!in)
-               return -1;
+       try
+       {
+               IO::File inf(fn.str());
+               IO::Buffered in(inf);
 
-       if(verbose>=3)
-               cout<<"Reading "<<fn<<'\n';
+               if(verbose>=3)
+                       cout<<"Reading "<<fn<<'\n';
 
-       DataFile::Parser parser(in, fn.str());
-       Loader loader(*this, fn.subpath(0, fn.size()-1));
-       loader.load(parser);
+               DataFile::Parser parser(in, fn.str());
+               Loader loader(*this, fn.subpath(0, fn.size()-1));
+               loader.load(parser);
+       }
+       catch(const IO::FileNotFound &)
+       {
+               return -1;
+       }
 
        return 0;
 }