]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- use exception instead of assert
authorArvin Schnell <aschnell@suse.de>
Wed, 20 Apr 2011 10:18:31 +0000 (12:18 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 20 Apr 2011 10:18:31 +0000 (12:18 +0200)
snapper/Enum.h

index 201de86b9279df3d8ab87dda4cd964bd615bb437..de22974ca4ee713dce771f17e499683cc8223d2f 100644 (file)
 #define ENUM_H
 
 
-#include <assert.h>
 #include <string>
 #include <vector>
 #include <algorithm>
+#include <exception>
 
 #include "snapper/Snapshot.h"
 #include "snapper/AppUtil.h"
@@ -39,6 +39,13 @@ namespace snapper
     using std::vector;
 
 
+    struct OutOfRangeException : public std::exception
+    {
+       explicit OutOfRangeException() throw() {}
+       virtual const char* what() const throw() { return "out of range"; }
+    };
+
+
     template <typename EnumType> struct EnumInfo {};
 
     template <> struct EnumInfo<SnapshotType> { static const vector<string> names; };
@@ -53,7 +60,8 @@ namespace snapper
 
        // Comparisons must not be done with type of enum since the enum may
        // define comparison operators.
-       assert((size_t)(value) < names.size());
+       if ((size_t)(value) >= names.size())
+           throw OutOfRangeException();
 
        return names[value];
     }