mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-28 16:20:12 +01:00
Define an AudacityException subclass for assertion violations
This commit is contained in:
42
src/InconsistencyException.cpp
Normal file
42
src/InconsistencyException.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// InconsistencyException.cpp
|
||||
//
|
||||
//
|
||||
// Created by Paul Licameli on 11/27/16.
|
||||
//
|
||||
//
|
||||
|
||||
#include "Audacity.h"
|
||||
#include "InconsistencyException.h"
|
||||
|
||||
InconsistencyException::~InconsistencyException()
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr< AudacityException > InconsistencyException::Move()
|
||||
{
|
||||
return std::unique_ptr< AudacityException >
|
||||
{ safenew InconsistencyException{ std::move( *this ) } };
|
||||
}
|
||||
|
||||
wxString InconsistencyException::ErrorMessage() const
|
||||
{
|
||||
// Shorten the path
|
||||
wxString path { file };
|
||||
auto sub = wxString{ wxFILE_SEP_PATH } + "src" + wxFILE_SEP_PATH;
|
||||
auto index = path.Find(sub);
|
||||
if (index != wxNOT_FOUND)
|
||||
path = path.Mid(index + sub.size());
|
||||
|
||||
#ifdef __func__
|
||||
return wxString::Format(
|
||||
_("Internal error in %s at %s line %d.\nPlease inform the Audacity team at feedback@audacityteam.org."),
|
||||
func, path, line
|
||||
);
|
||||
#else
|
||||
return wxString::Format(
|
||||
_("Internal error at %s line %d.\nPlease inform the Audacity team at feedback@audacityteam.org."),
|
||||
path, line
|
||||
);
|
||||
#endif
|
||||
}
|
||||
68
src/InconsistencyException.h
Normal file
68
src/InconsistencyException.h
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// InconsistencyException.h
|
||||
//
|
||||
//
|
||||
// Created by Paul Licameli on 11/27/16.
|
||||
//
|
||||
// Some errors that formerly were assertion violations now throw exceptions,
|
||||
// even in production code. These may be violations of function preconditions
|
||||
// or the results of logical errors internal to functions. These conditions
|
||||
// are supposed to be deducible statically as never happening.
|
||||
//
|
||||
|
||||
#ifndef __AUDACITY_INCONSISTENCY_EXCEPTION__
|
||||
#define __AUDACITY_INCONSISTENCY_EXCEPTION__
|
||||
|
||||
#include "AudacityException.h"
|
||||
|
||||
class InconsistencyException final : public MessageBoxException
|
||||
{
|
||||
public:
|
||||
InconsistencyException() {}
|
||||
|
||||
explicit InconsistencyException
|
||||
( const char *fn, const char *f, unsigned l )
|
||||
: func { fn }, file { f }, line { l }
|
||||
{}
|
||||
|
||||
InconsistencyException(InconsistencyException&& that)
|
||||
: MessageBoxException(std::move(that))
|
||||
{}
|
||||
InconsistencyException &operator = (InconsistencyException &&that)
|
||||
{
|
||||
if (this != &that)
|
||||
operator= (std::move(that));
|
||||
return *this;
|
||||
}
|
||||
|
||||
~InconsistencyException() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr< AudacityException > Move() override;
|
||||
|
||||
// Format a default, internationalized error message for this exception.
|
||||
wxString ErrorMessage() const override;
|
||||
|
||||
const char *func {};
|
||||
const char *file {};
|
||||
unsigned line {};
|
||||
};
|
||||
|
||||
// This macro constructs this exception type, using C++ preprocessor to identify
|
||||
// the source code location.
|
||||
|
||||
#ifdef __func__
|
||||
|
||||
#define CONSTRUCT_INCONSISTENCY_EXCEPTION \
|
||||
InconsistencyException( __func__, __FILE__ , __LINE__ )
|
||||
|
||||
#else
|
||||
|
||||
#define CONSTRUCT_INCONSISTENCY_EXCEPTION \
|
||||
InconsistencyException( "", __FILE__ , __LINE__ )
|
||||
|
||||
#endif
|
||||
|
||||
#define THROW_INCONSISTENCY_EXCEPTION throw CONSTRUCT_INCONSISTENCY_EXCEPTION
|
||||
|
||||
#endif
|
||||
@@ -146,6 +146,8 @@ audacity_SOURCES = \
|
||||
HistoryWindow.h \
|
||||
ImageManipulation.cpp \
|
||||
ImageManipulation.h \
|
||||
InconsistencyException.cpp \
|
||||
InconsistencyException.h \
|
||||
InterpolateAudio.cpp \
|
||||
InterpolateAudio.h \
|
||||
LabelDialog.cpp \
|
||||
|
||||
Reference in New Issue
Block a user