1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Define an AudacityException subclass for assertion violations

This commit is contained in:
Paul Licameli 2016-11-27 08:39:11 -05:00
parent df077d171a
commit f1cce8aa78
6 changed files with 126 additions and 0 deletions

View File

@ -1216,6 +1216,7 @@
5ED1D0AE1CDE55BD00471E3C /* OverlayPanel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5ED1D0AB1CDE55BD00471E3C /* OverlayPanel.cpp */; };
5ED1D0B11CDE560C00471E3C /* BackedPanel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5ED1D0AF1CDE560C00471E3C /* BackedPanel.cpp */; };
5EF17C231D1F0A690090A642 /* ScrubbingToolBar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EF17C211D1F0A690090A642 /* ScrubbingToolBar.cpp */; };
5EF958851DEB121800191280 /* InconsistencyException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EF958831DEB121800191280 /* InconsistencyException.cpp */; };
8406A93812D0F2510011EA01 /* EQDefaultCurves.xml in Resources */ = {isa = PBXBuildFile; fileRef = 8406A93712D0F2510011EA01 /* EQDefaultCurves.xml */; };
8484F31413086237002DF7F0 /* DeviceManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8484F31213086237002DF7F0 /* DeviceManager.cpp */; };
ED15214D163C22F000451B5F /* lsr.c in Sources */ = {isa = PBXBuildFile; fileRef = ED152123163C220300451B5F /* lsr.c */; };
@ -3007,6 +3008,8 @@
5ED1D0B01CDE560C00471E3C /* BackedPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackedPanel.h; sourceTree = "<group>"; };
5EF17C211D1F0A690090A642 /* ScrubbingToolBar.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrubbingToolBar.cpp; sourceTree = "<group>"; };
5EF17C221D1F0A690090A642 /* ScrubbingToolBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrubbingToolBar.h; sourceTree = "<group>"; };
5EF958831DEB121800191280 /* InconsistencyException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InconsistencyException.cpp; sourceTree = "<group>"; };
5EF958841DEB121800191280 /* InconsistencyException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InconsistencyException.h; sourceTree = "<group>"; };
82FF184D13CF01A600C1B664 /* dBTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = dBTable.cpp; path = sbsms/src/dBTable.cpp; sourceTree = "<group>"; };
82FF184E13CF01A600C1B664 /* dBTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = dBTable.h; path = sbsms/src/dBTable.h; sourceTree = "<group>"; };
82FF184F13CF01A600C1B664 /* slide.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = slide.cpp; path = sbsms/src/slide.cpp; sourceTree = "<group>"; };
@ -3862,6 +3865,7 @@
28501E9D0CEECEF80029ABAA /* HelpText.cpp */,
1790B07909883BFD008A330A /* HistoryWindow.cpp */,
1790B07B09883BFD008A330A /* ImageManipulation.cpp */,
5EF958831DEB121800191280 /* InconsistencyException.cpp */,
1790B09909883BFD008A330A /* Internat.cpp */,
28EBA7FD0A78FAF800C8BB1F /* InterpolateAudio.cpp */,
280828530A75E0D0000002EF /* LabelDialog.cpp */,
@ -3952,6 +3956,7 @@
28501E9E0CEECEF80029ABAA /* HelpText.h */,
1790B07A09883BFD008A330A /* HistoryWindow.h */,
1790B07C09883BFD008A330A /* ImageManipulation.h */,
5EF958841DEB121800191280 /* InconsistencyException.h */,
1790B09A09883BFD008A330A /* Internat.h */,
28EBA7FE0A78FAF800C8BB1F /* InterpolateAudio.h */,
280828540A75E0D0000002EF /* LabelDialog.h */,
@ -7495,6 +7500,7 @@
2891B2870C531D2C0044FBE3 /* FindClipping.cpp in Sources */,
283AA0EB0C56ED08002CBD34 /* ErrorDialog.cpp in Sources */,
28501EA10CEECEF80029ABAA /* HelpText.cpp in Sources */,
5EF958851DEB121800191280 /* InconsistencyException.cpp in Sources */,
28501EA20CEECEF80029ABAA /* SplashDialog.cpp in Sources */,
28501EAA0CEED0670029ABAA /* LoadVamp.cpp in Sources */,
5ED1D0AD1CDE55BD00471E3C /* Overlay.cpp in Sources */,

View 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
}

View 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

View File

@ -146,6 +146,8 @@ audacity_SOURCES = \
HistoryWindow.h \
ImageManipulation.cpp \
ImageManipulation.h \
InconsistencyException.cpp \
InconsistencyException.h \
InterpolateAudio.cpp \
InterpolateAudio.h \
LabelDialog.cpp \

View File

@ -161,6 +161,7 @@
<ClCompile Include="..\..\..\src\import\ImportGStreamer.cpp" />
<ClCompile Include="..\..\..\src\import\MultiFormatReader.cpp" />
<ClCompile Include="..\..\..\src\import\SpecPowerMeter.cpp" />
<ClCompile Include="..\..\..\src\InconsistencyException.cpp" />
<ClCompile Include="..\..\..\src\Internat.cpp" />
<ClCompile Include="..\..\..\src\InterpolateAudio.cpp" />
<ClCompile Include="..\..\..\src\LabelDialog.cpp" />
@ -439,6 +440,7 @@
<ClInclude Include="..\..\..\src\import\ImportGStreamer.h" />
<ClInclude Include="..\..\..\src\import\MultiFormatReader.h" />
<ClInclude Include="..\..\..\src\import\SpecPowerMeter.h" />
<ClInclude Include="..\..\..\src\InconsistencyException.h" />
<ClInclude Include="..\..\..\src\MemoryX.h" />
<ClInclude Include="..\..\..\src\ModuleManager.h" />
<ClInclude Include="..\..\..\src\NumberScale.h" />

View File

@ -890,6 +890,9 @@
<ClCompile Include="..\..\..\src\AudacityException.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\InconsistencyException.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\src\AboutDialog.h">
@ -1807,6 +1810,9 @@
<ClInclude Include="..\..\..\src\AudacityException.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\InconsistencyException.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\..\audacity.ico">