From 58fa55cf44c8b87ae3edb8f24fbac128649a7255 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 31 Mar 2022 23:52:06 -0700 Subject: Added real exceptions based on QException. These may not be stl compatible, which would be sad. They seem to work in practice, though. --- c++-qt/src/dictionary.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'c++-qt/src/dictionary.cpp') diff --git a/c++-qt/src/dictionary.cpp b/c++-qt/src/dictionary.cpp index 9b528f1..10ec6c5 100644 --- a/c++-qt/src/dictionary.cpp +++ b/c++-qt/src/dictionary.cpp @@ -13,6 +13,9 @@ #include "gats-qt/string.h" #include "gats-qt/list.h" +#include "gats-qt/parseexception.h" +#include "gats-qt/typeexception.h" + Gats::Dictionary::Dictionary() { } @@ -51,7 +54,7 @@ void Gats::Dictionary::write( QIODevice &rOut ) const rOut.write("e", 1 ); } -void Gats::Dictionary::read( QIODevice &rIn, char cType ) +void Gats::Dictionary::read( QIODevice &rIn, char /*cType*/ ) { for(;;) { @@ -60,7 +63,7 @@ void Gats::Dictionary::read( QIODevice &rIn, char cType ) if( cNext == 'e' ) break; if( cNext != 's' ) - throw "PUT GOOD EXCEPTION HERE"; + throw ParseException("Bad format reading binary Gats Dictionary."); Gats::String sKey; sKey.read( rIn, cNext ); @@ -243,7 +246,7 @@ bool Gats::Dictionary::valueBool( const QByteArray &sKey ) { Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as bool but isn't."); return pOb->getValue(); } @@ -252,7 +255,7 @@ int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) { Gats::Integer *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as int but isn't."); return pOb->getValue(); } @@ -261,7 +264,7 @@ double Gats::Dictionary::valueFloat( const QByteArray &sKey ) { Gats::Float *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as float but isn't."); return pOb->getValue(); } @@ -270,7 +273,7 @@ QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) { Gats::String *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as str but isn't."); return *pOb; } @@ -279,7 +282,7 @@ Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) { Gats::List *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as list but isn't."); return pOb; } @@ -288,7 +291,7 @@ Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) { Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as dict but isn't."); return pOb; } @@ -297,7 +300,7 @@ bool Gats::Dictionary::valueBool( const QByteArray &sKey ) const { Gats::Boolean *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as bool but isn't."); return pOb->getValue(); } @@ -306,7 +309,7 @@ int64_t Gats::Dictionary::valueInt( const QByteArray &sKey ) const { Gats::Integer *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as int but isn't."); return pOb->getValue(); } @@ -315,7 +318,7 @@ double Gats::Dictionary::valueFloat( const QByteArray &sKey ) const { Gats::Float *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as float but isn't."); return pOb->getValue(); } @@ -324,7 +327,7 @@ QByteArray Gats::Dictionary::valueStr( const QByteArray &sKey ) const { Gats::String *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as str but isn't."); return *pOb; } @@ -333,7 +336,7 @@ Gats::List *Gats::Dictionary::valueList( const QByteArray &sKey ) const { Gats::List *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as list but isn't."); return pOb; } @@ -342,7 +345,7 @@ Gats::Dictionary *Gats::Dictionary::valueDict( const QByteArray &sKey ) const { Gats::Dictionary *pOb = dynamic_cast( value( sKey ) ); if( !pOb ) - throw "PUT GOOD EXCEPTION HERE"; + throw TypeException("Dictionary value requested as dict but isn't."); return pOb; } -- cgit v1.2.3