Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / C++ [игнор отключен] [закрыт для гостей] / Необработанное исключение в boost / 2 сообщений из 2, страница 1 из 1
06.04.2014, 11:17
    #38606348
Alsou
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Необработанное исключение в boost
Я использую библиотеку boost для отправки команд в com-порт, но у меня при компиляции вылезают исключения http://pixs.ru/showimage/vapng_9051629_11569331.png.

вот сама прога

Код: plaintext
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.
//main.cpp

//#include <Windows.h>
#include <iostream>
//#include <stdio>
//#include <conio>
#include "h.h"

#include "SimpleSerial.h"

using namespace std;
using namespace boost;

int main(int argc, char* argv[])
{


   //try {
         SimpleSerial serial("COM3",115200);
         while(1){
  
  cout<<"Read data from DATA register.\n"<<endl;    

  int data;
  data = Inp32(888);
  cout<<"10: "<<data<<endl;

  char number[20];
  itoa(data,number,2);
  cout<<" 2: "<<number<<endl;
    
  
    if(number[0]=='1' && number[1]=='1' && number[2]=='1' && number[3]=='1' && number[4]=='1' && number[5]=='1' && number[6]=='1' && number[7]=='1')
    {
        serial.writeString("$KE,REL,1,1\r\n");
    }
    else 
    {
        serial.writeString("$KE,REL,1,0\r\n");
    }
        
    if(number[0]=='1' && number[1]=='0' && number[2]=='0' && number[3]=='0' && number[4]=='0' && number[5]=='0' && number[6]=='0' && number[7]=='0')
    {
        serial.writeString("$KE,REL,2,1\r\n");
    }    
    else 
    {
        serial.writeString("$KE,REL,2,0\r\n");
    }
    if(number[0]=='0' && number[1]=='1' && number[2]=='0' && number[3]=='0' && number[4]=='0' && number[5]=='0' && number[6]=='0' && number[7]=='0')
    {
        serial.writeString("$KE,REL,3,1\r\n");
    }    
    else 
    {
        serial.writeString("$KE,REL,3,0\r\n");
    }
    if(number[0]=='0' && number[1]=='0' && number[2]=='1' && number[3]=='0' && number[4]=='0' && number[5]=='0' && number[6]=='0' && number[7]=='0')
    {
        serial.writeString("$KE,REL,4,1\r\n");
    }    
    else 
    {
        serial.writeString("$KE,REL,4,0\r\n");
    }

        cout<<serial.readLine()<<endl;

    //} catch(boost::system::system_error& e)
    //{
       // cout<<"Error: "<<e.what()<<endl;
           FILE * fo;
   fo=fopen("fajl6.txt","wt");
    fprintf(fo,"%s\n",number);
    fclose(fo);
       Sleep(5 * 1000); 
     
    }
   return 0;
   
}


Код: plaintext
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.
//SimpleSerial.h

#include <boost/asio.hpp>

class SimpleSerial
{
public:
    /**
     * Constructor.
     * \param port device name, example "/dev/ttyUSB0" or "COM4"
     * \param baud_rate communication speed, example 9600 or 115200
     * \throws boost::system::system_error if cannot open the
     * serial device
     */
    SimpleSerial(std::string port, unsigned int baud_rate)
    : io(), serial(io,port)
    {
        serial.set_option(boost::asio::serial_port_base::baud_rate(baud_rate));
    }

    /**
     * Write a string to the serial device.
     * \param s string to write
     * \throws boost::system::system_error on failure
     */
    void writeString(std::string s)
    {
        boost::asio::write(serial,boost::asio::buffer(s.c_str(),s.size()));
    }

    /**
     * Blocks until a line is received from the serial device.
     * Eventual '\n' or '\r\n' characters at the end of the string are removed.
     * \return a string containing the received line
     * \throws boost::system::system_error on failure
     */
    std::string readLine()
    {
        //Reading data char by char, code is optimized for simplicity, not speed
        using namespace boost;
        char c;
        std::string result;
        for(;;)
        {
            asio::read(serial,asio::buffer(&c,1));
            switch(c)
            {
                case '\r':
                    break;
                case '\n':
                    return result;
                default:
                    result+=c;
            }
        }
    }

private:
    boost::asio::io_service io;
    boost::asio::serial_port serial;
};


//end SimpleSerial.h



и вместе с ошибкой исключением вылезают потом коды throw_exception.hpp и throw_error.ipp
Код: plaintext
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.
// throw_exception.hpp 
#ifndef UUID_AA15E74A856F11E08B8D93F24824019B
#define UUID_AA15E74A856F11E08B8D93F24824019B
#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma GCC system_header
#endif
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma warning(push,1)
#endif

// MS compatible compilers support #pragma once

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

//
//  boost/throw_exception.hpp
//
//  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//  Copyright (c) 2008-2009 Emil Dotchevski and Reverge Studios, Inc.
//
//  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)
//
//  http://www.boost.org/libs/utility/throw_exception.html
//

#include <boost/exception/detail/attribute_noreturn.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config.hpp>
#include <exception>

#if !defined( BOOST_EXCEPTION_DISABLE ) && defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0x593) )
# define BOOST_EXCEPTION_DISABLE
#endif

#if !defined( BOOST_EXCEPTION_DISABLE ) && defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1310 )
# define BOOST_EXCEPTION_DISABLE
#endif

#if !defined( BOOST_EXCEPTION_DISABLE )
# include <boost/exception/exception.hpp>
#if !defined(BOOST_THROW_EXCEPTION_CURRENT_FUNCTION)
# include <boost/current_function.hpp>
# define BOOST_THROW_EXCEPTION_CURRENT_FUNCTION BOOST_CURRENT_FUNCTION
#endif
# define BOOST_THROW_EXCEPTION(x) ::boost::exception_detail::throw_exception_(x,BOOST_THROW_EXCEPTION_CURRENT_FUNCTION,__FILE__,__LINE__)
#else
# define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x)
#endif

namespace boost
{
#ifdef BOOST_NO_EXCEPTIONS

void throw_exception( std::exception const & e ); // user defined

#else

inline void throw_exception_assert_compatibility( std::exception const & ) { }

template<class E> BOOST_ATTRIBUTE_NORETURN inline void throw_exception( E const & e )
{
    //All boost exceptions are required to derive from std::exception,
    //to ensure compatibility with BOOST_NO_EXCEPTIONS.
    throw_exception_assert_compatibility(e);

#ifndef BOOST_EXCEPTION_DISABLE
    throw enable_current_exception(enable_error_info(e));
#else
    throw e;
#endif
}

#endif

#if !defined( BOOST_EXCEPTION_DISABLE )
    namespace
    exception_detail
    {
        template <class E>
        BOOST_ATTRIBUTE_NORETURN
        void
        throw_exception_( E const & x, char const * current_function, char const * file, int line )
        {
            boost::throw_exception(
                set_info(
                    set_info(
                        set_info(
                            enable_error_info(x),
                            throw_function(current_function)),
                        throw_file(file)),
                    throw_line(line)));
        }
    }
#endif
} // namespace boost

#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma warning(pop)
#endif
#endif


Код: plaintext
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.
// detail/impl/throw_error.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// 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)
//

#ifndef BOOST_ASIO_DETAIL_IMPL_THROW_ERROR_IPP
#define BOOST_ASIO_DETAIL_IMPL_THROW_ERROR_IPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)


#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/system/system_error.hpp>

#include <boost/asio/detail/push_options.hpp>

namespace boost {
namespace asio {
namespace detail {

void do_throw_error(const boost::system::error_code& err)
{
  boost::system::system_error e(err);
  boost::asio::detail::throw_exception(e);
}

void do_throw_error(const boost::system::error_code& err, const char* location)
{
  boost::system::system_error e(err, location);
  boost::asio::detail::throw_exception(e);
}

} // namespace detail
} // namespace asio
} // namespace boost

#include <boost/asio/detail/pop_options.hpp>

#endif // BOOST_ASIO_DETAIL_IMPL_THROW_ERROR_IPP



Можете подсказать как исправить эту ошибку?
...
Рейтинг: 0 / 0
06.04.2014, 14:47
    #38606457
smald
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Необработанное исключение в boost
Alsou,

Код: plaintext
1.
if(number[0]=='1' && number[1]=='0' && number[2]=='0' && number[3]=='0' && number[4]=='0' && number[5]=='0' && number[6]=='0' && number[7]=='0')



Где Вас учили так массивы сравнивать?
Для этого нужно memcmp, strncmp применять, в целях
производительности.
А ошибка компиляции говорит, что исключения
не обработаны, будь добр расписать как надо.
...
Рейтинг: 0 / 0
Форумы / C++ [игнор отключен] [закрыт для гостей] / Необработанное исключение в boost / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]