Jeongik Cha | 1199caa | 2021-07-20 12:32:58 +0900 | [diff] [blame] | 1 | /* ---------------------------------------------------------------------------- |
| 2 | libconfig - A library for processing structured configuration files |
| 3 | Copyright (C) 2005-2010 Mark A Lindner |
| 4 | |
| 5 | This file is part of libconfig. |
| 6 | |
| 7 | This library is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU Lesser General Public License |
| 9 | as published by the Free Software Foundation; either version 2.1 of |
| 10 | the License, or (at your option) any later version. |
| 11 | |
| 12 | This library is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | Lesser General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Library General Public |
| 18 | License along with this library; if not, see |
| 19 | <http://www.gnu.org/licenses/>. |
| 20 | ---------------------------------------------------------------------------- |
| 21 | */ |
| 22 | |
| 23 | #include <iostream> |
| 24 | #include <iomanip> |
| 25 | #include <cstdlib> |
| 26 | #include <libconfig.h++> |
| 27 | |
| 28 | using namespace std; |
| 29 | using namespace libconfig; |
| 30 | |
| 31 | // This example demonstrates the handling of parsing errors in |
| 32 | // 'invalid.cfg'. |
| 33 | |
| 34 | int main(int argc, char **argv) |
| 35 | { |
| 36 | Config cfg; |
| 37 | |
| 38 | try |
| 39 | { |
| 40 | cfg.readFile("invalid.cfg"); |
| 41 | } |
| 42 | catch(const FileIOException &fioex) |
| 43 | { |
| 44 | std::cerr << "File I/O error" << std::endl; |
| 45 | return(EXIT_FAILURE); |
| 46 | } |
| 47 | catch(const ParseException &pex) |
| 48 | { |
| 49 | std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() |
| 50 | << " - " << pex.getError() << std::endl; |
| 51 | return(EXIT_FAILURE); |
| 52 | } |
| 53 | |
| 54 | return(EXIT_SUCCESS); |
| 55 | } |
| 56 | |
| 57 | // eof |