Boost logo

Boost :

From: rajesh daggumati (rajeshdaggumati9999_at_[hidden])
Date: 2021-11-18 17:33:20


Hi Team,

While doing typecasting from boost::any to DecodeErrorPayload_t, its
throwing bad_any_cast ..

class RegisterIONotification

{

  public:

       enum NotifyType {

                   TypeUnknown,

                  TypeRegTx,

                  TypeRegRx,

                 TypeDecodeError

              };

              NotifyType Type;

              boost::any Payload;

              typedef boost::tuple<std::string, BinaryBuffer_t>
DecodeErrorPayload_t;

  RegisterIONotification(NotifyType type;,boost::any payload)

                             {

                                           Type(type);

                                           Payload(payload);

                             }

};

I have called RegisterIONotification from other class function.

void RegisterIOThreaded::OnDecodeError( const std::string& error,
BinaryBuffer_t data )

    {

        RegisterIONotification
notify(RegisterIONotification::TypeDecodeError ,make_tuple(error, data));

        .....

                             ....

                             ...

    }

While testing, I am getting bad_any_cast exception.

TEST_F(...,...)

   {

        RegisterIONotification notify =
sink.GetDataById(ID::NOTIFY_COMMS_STATUS,
0).GetValue<RegisterIONotification>();

        ASSERT_EQ(RegisterIONotification::TypeDecodeError,
notify.Type); //passed

         RegisterIONotification::DecodeErrorPayload_t payload;

        ASSERT_NO_THROW(payload =
boost::any_cast<RegisterIONotification::DecodeErrorPayload_t>(notify.Payload));//
Here its got failed…Please help me to fix this.

   }

Regards,

Rajesh D


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk