Add KI_PARAM_ERROR, similar to std::invalid_argument but using wxString instead of std::string to throw errors.

std::invalid_argument does not work fine with translated strings as argument for message.
(the translated message is incorrectly or not displayed if it contains non ascii8 chars, at least on Windows).
KI_PARAM_ERROR can be throw-ed with a translatable/translated string (a wxString)
This commit is contained in:
jean-pierre charras 2018-06-05 13:26:37 +02:00
parent 58814e838d
commit a288d6199e
4 changed files with 38 additions and 6 deletions

View File

@ -382,9 +382,10 @@ void SIM_PLOT_FRAME::AddTuner( SCH_COMPONENT* aComponent )
m_tuners.push_back( tuner );
m_tunePanel->Layout();
}
catch( ... )
catch( const KI_PARAM_ERROR& e )
{
// Sorry, no bonus
DisplayError( nullptr, e.What() );
}
}

View File

@ -31,18 +31,19 @@
#include <wx/numformatter.h>
#include <confirm.h>
#include <common.h>
#include <ki_exception.h>
SPICE_VALUE::SPICE_VALUE( const wxString& aString )
{
char buf[8] = { 0, };
if( aString.IsEmpty() )
throw std::invalid_argument( _( "Spice value cannot be empty" ) );
throw KI_PARAM_ERROR( _( "Spice value cannot be empty" ) );
LOCALE_IO dummy; // All numeric values should be in "C" locale(decimal separator = .)
if( sscanf( (const char*) aString.c_str(), "%lf%7s", &m_base, buf ) == 0 )
throw std::invalid_argument( _( "Invalid Spice value string" ) );
throw KI_PARAM_ERROR( _( "Invalid Spice value string" ) );
if( *buf == 0 )
{

View File

@ -36,6 +36,7 @@ TUNER_SLIDER::TUNER_SLIDER( SIM_PLOT_FRAME* aFrame, wxWindow* aParent, SCH_COMPO
const wxString compName = aComponent->GetField( REFERENCE )->GetText();
m_name->SetLabel( compName );
m_value = SPICE_VALUE( aComponent->GetField( VALUE )->GetText() );
m_changed = false;
m_spiceName = aFrame->GetExporter()->GetSpiceDevice( compName ).Lower();
@ -157,7 +158,7 @@ void TUNER_SLIDER::onMaxTextEnter( wxCommandEvent& event )
SPICE_VALUE newMax( m_maxText->GetValue() );
SetMax( newMax );
}
catch( std::exception& )
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_maxText->SetValue( m_max.ToOrigString() );
@ -173,7 +174,7 @@ void TUNER_SLIDER::onValueTextEnter( wxCommandEvent& event )
SetValue( newCur );
m_changed = true;
}
catch( std::exception& )
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_valueText->SetValue( m_value.ToOrigString() );
@ -188,7 +189,7 @@ void TUNER_SLIDER::onMinTextEnter( wxCommandEvent& event )
SPICE_VALUE newMin( m_minText->GetValue() );
SetMin( newMin );
}
catch( std::exception& )
catch( const KI_PARAM_ERROR& )
{
// Restore the previous value
m_minText->SetValue( m_min.ToOrigString() );

View File

@ -37,6 +37,35 @@
/// macro which captures the "call site" values of __FILE_, __FUNCTION__ & __LINE__
#define THROW_IO_ERROR( msg ) throw IO_ERROR( msg, __FILE__, __FUNCTION__, __LINE__ )
/**
* class KI_PARAM_ERROR
* is a class used to hold a translatable error message and may be used when throwing exceptions
* containing a translated error message.
*/
class KI_PARAM_ERROR // similar to std::invalid_argument for instance
{
public:
/**
* Constructor
*/
KI_PARAM_ERROR( const wxString& aMessage )
{
m_message = aMessage;
}
KI_PARAM_ERROR() {}
const wxString What() const
{
return m_message;
}
virtual ~KI_PARAM_ERROR() throw () {}
private:
wxString m_message;
};
/**
* Struct IO_ERROR