Skip to content

Commit

Permalink
libcore|FS: Improved error messages thrown in Folder::locate()
Browse files Browse the repository at this point in the history
The error message now makes a distinction between a file that was not
found at all, and a file that was of an unexpected type.
  • Loading branch information
skyjake committed Oct 17, 2015
1 parent 8d76c82 commit 0683b81
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions doomsday/sdk/libcore/include/de/filesys/folder.h
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG2_FOLDER_H
Expand Down Expand Up @@ -101,7 +101,7 @@ class DENG2_PUBLIC Folder : public File
virtual ~Folder();

String describe() const;

String describeFeeds() const;

/**
Expand Down Expand Up @@ -247,14 +247,21 @@ class DENG2_PUBLIC Folder : public File
*/
template <typename Type>
Type &locate(String const &path) const {
Type *found = tryLocate<Type>(path);
File *found = tryLocateFile(path);
if(!found) {
/// @throw NotFoundError Path didn't exist, or the located file had
/// an incompatible type.
throw NotFoundError("Folder::locate", "\"" + path +"\" was not found or had incompatible type "
/// @throw NotFoundError Path didn't exist.
throw NotFoundError("Folder::locate", "\"" + path + "\" was not found "
"(in " + description() + ")");
}
return *found;
if(Type *casted = dynamic_cast<Type *>(found)) {
return *casted;
}
/// @throw NotFoundError Found file could not be cast to the
/// requested type.
throw NotFoundError("Folder::locate",
QString("%1 has incompatible type; wanted %2")
.arg(found->description())
.arg(DENG2_TYPE_NAME(Type)));
}

/**
Expand Down

0 comments on commit 0683b81

Please sign in to comment.