00001 /* 00002 * Metroid Password Generator 00003 * Copyright (C) 2005,2007-2008 emuWorks 00004 * http://games.technoplaza.net/ 00005 * 00006 * This file is part of Metroid Password Generator. 00007 * 00008 * Metroid Password Generator is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * Metroid Password Generator is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with Metroid Password Generator; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 // $Id: InvalidPasswordException.hh,v 1.7 2008/12/17 00:23:12 jdratlif Exp $ 00024 00025 #ifndef MPG_INVALIDPASSWORDEXCEPTION_HH_ 00026 #define MPG_INVALIDPASSWORDEXCEPTION_HH_ 00027 00028 #include <stdexcept> 00029 #include <string> 00030 00031 namespace mpg { 00032 /// enumeration for the invalid password errors 00033 enum PasswordError { 00034 INVALID_ALPHABET, INVALID_CHECKSUM, INVALID_LENGTH 00035 }; 00036 00037 /** 00038 * Exception thrown when an invalid password is given, such as an invalid 00039 * character (outside the Metroid alphabet), invalid checksum, or invalid 00040 * password length. 00041 */ 00042 class InvalidPasswordException : public std::runtime_error { 00043 private: 00044 enum PasswordError error; 00045 00046 public: 00047 /** 00048 * Creates a new InvalidPasswordException. 00049 * 00050 * @param message The error messsage. 00051 * @param error The password error. 00052 */ 00053 InvalidPasswordException(const std::string &message, 00054 enum PasswordError error); 00055 00056 /** 00057 * Gets the error that triggered this InvalidPasswordException. 00058 * 00059 * @return The error. 00060 */ 00061 enum PasswordError getError() const; 00062 }; 00063 00064 inline InvalidPasswordException::InvalidPasswordException( 00065 const std::string &message, enum PasswordError error) : 00066 std::runtime_error(message), error(error) {} 00067 inline enum PasswordError InvalidPasswordException::getError() const 00068 { return error; } 00069 } 00070 00071 #endif 00072