Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.


    Copyright (c) 1998-2003 Joel de Guzman

    Use, modification and distribution is subject to the Boost Software
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
//  This sample demonstrates error handling as seen in the
//  Error Handling" chapter in the User's Guide.
#include <boost/spirit/core.hpp>
#include <boost/spirit/error_handling/exceptions.hpp>
#include <iostream>
#include <cassert>

using namespace std;
using namespace boost::spirit;

struct handler
    template <typename ScannerT, typename ErrorT>
    operator()(ScannerT const& /*scan*/, ErrorT const& /*error*/) const
        cout << "exception caught...Test concluded successfully" << endl;
        return error_status<>(error_status<>::fail);

    cout << "/////////////////////////////////////////////////////////\n\n";
    cout << "\t\tExceptions Test...\n\n";
    cout << "/////////////////////////////////////////////////////////\n\n";

    assertion<int>  expect(0);
    guard<int>      my_guard;
    rule<> start = 
        my_guard(ch_p('a') >> 'b' >> 'c' >> expect( ch_p('d') ))

    bool r = parse("abcx", start).full;

    return 0;