excpetion unhandled using boost

i dont know what is going wrong and I am beginning to panic.
trying to learn serialization with boost. accidentally deleted the file "scores.txt" that I created, I undid the deletion but the computer is angry, and it wants revenge, it just keeps giving me unhanded exceptions no matter what I do. how do I appease this monster without making sacrifices irl

jargon that it puts out if anyone understands it:

"Unhandled exception at 0x761DA6F2 in Project1.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0053EAE8."

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <cctype>
#include <boost/thread.hpp>
#include <boost/serialization/list.hpp>
//needed to conduct serialization
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
//needed to open and close files

using namespace std;
int points;

void question(const std::string& fname)
//this clears these values to 0 to ensure that the cypher is not disrupted
{
	vector<string> lines;
	ifstream file(fname);
	//this inputs the file "fname" from which the text files holding the football teams, characters and countries will be loaded, as i had trouble loading files individually
		if (!file) {
			cout << "Cannot open file " << fname << '\n';
			return;
			//if the any of the files are not present in the folder then this is printed to show the user that something is wrong, and gives them an idea of how it can be fixed
		}
	for (string line; getline(file, line); lines.push_back(line));
	const auto random_number{ rand() % lines.size() };
	const auto word{ lines[random_number] };
	const auto codes{ new int[word.length()] {} };
	//these lines find and identify the lines within a text file so that the entire word is selected instead of just the first letter and the word can be mixed upand then changed into numbers at the next code block
		for (size_t i = 0; i < word.length(); ++i)
			if (isalpha(static_cast<unsigned char>(word[i]))) {
				codes[i] = std::tolower(static_cast<unsigned char>(word[i])) - 'a' + 1;
				cout << codes[i] << ' ';
				//these lines change the identifed lines with the text file to the substitution cypher, changing each letter into the corresponding number in the alphabet
			}
	string answer;
	cout << "\nPlease input your answer (no capitals, no spaces): ";
	cin >> answer;
	cout << word;
	//this allows the user to input an answer, and after they have inputted an answer it will also show them the correct answer to see how far off they were(either completly wrong, or perhaps the wrong format)
		if (answer == word) {
			cout << "\nCorrect!\n\n";
			points++;
			//if the user gets the answer correct they are told as such and a point is added to their score
		}
		else cout << "\nIncorrect :(\n\n";
	//if the answer is incorrect they are told and are able to continue and do not gain any points
}
struct Quiz {
	string fname;
	string title;
	string catnum;
	/**i used a struct to created the actual quiz part of the game, as this was simpler than using public and private classes
	*the string fname is the text file containing the names
	*the title file is the name of the category in the quiz, for the game to output and for it to not contain underscores
	*the catnum is the number of the category, so that the game can tell the user what level they are on before it begins
	*/
};

class scores {
	int past, total;
public:
	scores() {}
	scores(int p, int t) :past(p), total(t) {}
	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive& ar, const unsigned int version)
	{
		ar& past;
		ar& total;
	}
	int getpoints() { return past; }
	int gettotal() { return total; }
};
/** serialization used to contain the players best score and the total amount of points they have gathered
* code adapted from Mike Morgan (2017)
* the class of scores is used with the integer parameters best and total
* it uses a default constructor (L67)
* it also uses a bespoke constructor which indicates that the ints of "b" and "t" are the same as "best" and "total"
* L69 allows the values of best and total to be accessed through boost serialization
* the use of & on L73 and L74 allows the input and output of these integers instead of one way with << or >>
*/


int main()
{
	std::list<int> data;
	try
	{
		std::ifstream in("newcategory.txt");
		boost::archive::text_iarchive ar(in);
		ar >> data;

	}
	catch (std::exception& ex)
	{
		std::cerr << ex.what();
	}
	{
		std::ofstream out("newcategory.txt");
		boost::archive::text_oarchive ar(out);
		ar << data;
	}
	/**
	*a simple serialization output to the file for the new category
	*it outputs to the file that is being created "newcategory.txt"
	*/

	const Quiz qz[]{ {"Premier_League_Teams.txt", "\nPremier League Football Teams!\n","first"},
	{"Premier_League_Teams.txt", "\nPremier League Football Teams!\n", "second"},
	{"Hobbit_Characters.txt", "\nHobbit Characters\n", "third"},
	{"Hobbit_Characters.txt", "\nHobbit Characters\n", "fourth"},
	{"South_American_Countries.txt", "\nSouth American Countries\n", "final"} };
	//these lines of code identify the text files from the stored folder, and also output the name of the round, as well as its position in the queue using the strings above
		srand(static_cast<unsigned int>(time(nullptr)));
	//seeds the random number generator and ensures it is not affected by previous launching of the code
		cout << "Richard Osman's house of Games: This round is in code.\n\n\n";
	cout << "The objective of this round is to unscramble the coded word.\n";
	cout << "You will be given the category as the clue\n";
	cout << "and you have to type out what you believe the answer to be, with a capital letter\n\n";
		//introductory text for the user to read
		string Name;
	cout << "But First, Enter your first name: ";
	getline(cin, Name);
	//this will allow the quiz to be personal to each player, displaying their name at key points and also their name next to their score.
		cout << "\nWelcome contestant " << Name << ". Are you ready to begin the quiz?\n";
	cout << "Please type yes to continue (case sensitive): ";
	string respond;
	cin >> respond;
	if (respond != "yes") {
		cout << "Maybe next time!\n";
		return 0;
		//this adds a degree of playability to the game, offering a quit game button, to increase immersion and the user experience
	}
	cout << "Good luck!\n";
	for (const auto& quiz : qz) {
		cout << "The " << quiz.catnum << " category is...\n" << quiz.title << '\n';
		//this tells the user the number of the category we are on, and what the category is
			question(quiz.fname);
		//this loads the question from the quiz data structure
		cout << Name << ", your score is " << points << " out of 5!\n";
		//after each answer is submitted the user is told their current score out of the total amount of questions
		std::list<scores> data;
		try
		{
			std::ifstream in("scores.txt");
			boost::archive::text_iarchive arch(in);
			arch >> data;
		}
		catch (std::exception* ex)
		{
			std::cerr << ex->what();
		}
		for (auto i : data)
		{
			std::cout << i.getpoints() << " previous " << i.gettotal() << " total " << std::endl;
		}
		data.push_back(scores(45454, 454));
		data.push_back(scores(1, 3));
		{
			std::ofstream out("scores.txt");
			boost::archive::text_oarchive arch(out);
			arch << data;
		}
	
	}
}
Have you run the program with your debugger? The debugger should be able to tell you exactly where it is encountering the problems.

Perhaps "catching" the "boost::archive::archive_exception" might lead to more information? But really running with the debugger will probably give you more information as to the location and cause of the problem.

Probably one of the files isn't opening.
You should add checks to ensure that a file actually opens after you open it.
im using visual studio debugger and ironically its saying no problems found. when I run the code it opens a second console on visual called "throw_exception.hpp" and on this console the issue is on line 37

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef BOOST_SERIALIZATION_THROW_EXCEPTION_HPP_INCLUDED
#define BOOST_SERIALIZATION_THROW_EXCEPTION_HPP_INCLUDED

// MS compatible compilers support #pragma once

#if defined(_MSC_VER)
# pragma once
#endif

//  boost/throw_exception.hpp
//
//  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/config.hpp>

#ifndef BOOST_NO_EXCEPTIONS
#include <exception>
#endif

namespace boost {
namespace serialization {

#ifdef BOOST_NO_EXCEPTIONS

BOOST_NORETURN inline void throw_exception(std::exception const & e) {
    ::boost::throw_exception(e);
}

#else

template<class E> BOOST_NORETURN inline void throw_exception(E const & e){
    throw e;
}

#endif

} // namespace serialization
} // namespace boost

#endif // #ifndef BOOST_SERIALIZATION_THROW_EXCEPTION_HPP_INCLUDED 
im very knew to the boost library so I have no idea what I'm doing or what I'm doing wrong
i just attempted to run again, but I ran "throw_exception.hpP" and not source.cpp and it opened yet another console this time named "basic_text_imprimitive.hpp". what the hell is happening

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP
#define BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP

// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif

/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_text_iprimitive.hpp

// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org for updates, documentation, and revision history.

// archives stored as text - note these are templated on the basic
// stream templates to accommodate wide (and other?) kind of characters
//
// Note the fact that on libraries without wide characters, ostream is
// not a specialization of basic_ostream which in fact is not defined
// in such cases.   So we can't use basic_ostream<IStream::char_type> but rather
// use two template parameters

#include <locale>
#include <cstddef> // size_t

#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
    using ::size_t;
    #if ! defined(BOOST_DINKUMWARE_STDLIB) && ! defined(__SGI_STL_PORT)
        using ::locale;
    #endif
} // namespace std
#endif

#include <boost/io/ios_state.hpp>
#include <boost/static_assert.hpp>

#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
#include <boost/archive/dinkumware.hpp>
#endif
#include <boost/serialization/throw_exception.hpp>
#include <boost/archive/codecvt_null.hpp>
#include <boost/archive/archive_exception.hpp>
#include <boost/archive/basic_streambuf_locale_saver.hpp>
#include <boost/archive/detail/abi_prefix.hpp> // must be the last header

namespace boost {
namespace archive {

/////////////////////////////////////////////////////////////////////////
// class basic_text_iarchive - load serialized objects from a input text stream
#if defined(_MSC_VER)
#pragma warning( push )
#pragma warning( disable : 4244 4267 )
#endif

template<class IStream>
class BOOST_SYMBOL_VISIBLE basic_text_iprimitive {
protected:
    IStream &is;
    io::ios_flags_saver flags_saver;
    io::ios_precision_saver precision_saver;

    #ifndef BOOST_NO_STD_LOCALE
    // note order! - if you change this, libstd++ will fail!
    // a) create new locale with new codecvt facet
    // b) save current locale
    // c) change locale to new one
    // d) use stream buffer
    // e) change locale back to original
    // f) destroy new codecvt facet
    boost::archive::codecvt_null<typename IStream::char_type> codecvt_null_facet;
    std::locale archive_locale;
    basic_istream_locale_saver<
        typename IStream::char_type,
        typename IStream::traits_type
    > locale_saver;
    #endif

    template<class T>
    void load(T & t)
    {
        if(is >> t)
            return;
        boost::serialization::throw_exception(
            archive_exception(archive_exception::input_stream_error)
        );
    }

    void load(char & t)
    {
        short int i;
        load(i);
        t = i;
    }
    void load(signed char & t)
    {
        short int i;
        load(i);
        t = i;
    }
    void load(unsigned char & t)
    {
        unsigned short int i;
        load(i);
        t = i;
    }

    #ifndef BOOST_NO_INTRINSIC_WCHAR_T
    void load(wchar_t & t)
    {
        BOOST_STATIC_ASSERT(sizeof(wchar_t) <= sizeof(int));
        int i;
        load(i);
        t = i;
    }
    #endif
    BOOST_ARCHIVE_OR_WARCHIVE_DECL
    basic_text_iprimitive(IStream  &is, bool no_codecvt);
    BOOST_ARCHIVE_OR_WARCHIVE_DECL
    ~basic_text_iprimitive();
public:
    BOOST_ARCHIVE_OR_WARCHIVE_DECL void
    load_binary(void *address, std::size_t count);
};

#if defined(_MSC_VER)
#pragma warning( pop )
#endif

} // namespace archive
} // namespace boost

#include <boost/archive/detail/abi_suffix.hpp> // pop pragmas

#endif // BOOST_ARCHIVE_BASIC_TEXT_IPRIMITIVE_HPP 



this one has an exception thrown on line 94, reading "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
"
Did you completely ignore my suggestion or did you add the tests to ensure that the files are open?
i checked, and they were opening. i found it easier to just start again and I'm back at the point I was previously
it seems to be an issue on the "access.hpp" console, but I have no idea what the issue is or how to fix it, it occurs on line 116 and that line says

 
        t.serialize(ar, file_version);


what should it be if not this?
im not sure what ive done but its fixed
Topic archived. No new replies allowed.