Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more standard exceptions and remove CRTError exception #252

Merged
merged 3 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions ebml/StdIOCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

#include "IOCallback.h"

#include <stdexcept>
#include <cerrno>

namespace libebml {

enum open_mode {
Expand All @@ -21,20 +18,6 @@ enum open_mode {
MODE_SAFE
};

class EBML_DLL_API CRTError:public std::runtime_error
{
// Variablen...
private:
int Error;

// Methoden...
public:
CRTError(int Error,const std::string&Description);
explicit CRTError(const std::string&Description,int Error=errno);

int getError() const noexcept { return Error; }
};

// This class is currently private to the library, so there's no MATROSKA_EXPORT.
class EBML_DLL_API StdIOCallback:public IOCallback
{
Expand Down
4 changes: 2 additions & 2 deletions src/EbmlBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
\author Julien Coloos <suiryc @ users.sf.net>
*/
#include <string>
#include <stdexcept>

#include "ebml/EbmlBinary.h"
#include "ebml/StdIOCallback.h"

namespace libebml {

Expand Down Expand Up @@ -85,7 +85,7 @@ filepos_t EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully)

Data = (GetSize() < std::numeric_limits<std::size_t>::max()) ? static_cast<binary *>(malloc(GetSize())) : nullptr;
if (Data == nullptr)
throw CRTError(std::string("Error allocating data"));
throw std::runtime_error("Error allocating data");
SetValueIsSet();
return input.read(Data, GetSize());
}
Expand Down
22 changes: 5 additions & 17 deletions src/StdIOCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,14 @@
#include <cassert>
#include <limits>
#include <sstream>
#include <ios>

#include "ebml/StdIOCallback.h"

using namespace std;

namespace libebml {

CRTError::CRTError(int nError, const std::string & Description)
:std::runtime_error(Description+": "+strerror(nError))
,Error(nError)
{
}

CRTError::CRTError(const std::string & Description,int nError)
:std::runtime_error(Description+": "+strerror(nError))
,Error(nError)
{
}


StdIOCallback::StdIOCallback(const char*Path, const open_mode aMode)
{
assert(Path!=nullptr);
Expand All @@ -56,7 +44,7 @@ StdIOCallback::StdIOCallback(const char*Path, const open_mode aMode)
if(File==nullptr) {
stringstream Msg;
Msg<<"Can't open stdio file \""<<Path<<"\" in mode \""<<Mode<<"\"";
throw CRTError(Msg.str());
throw ios_base::failure(Msg.str(), error_code{errno, std::system_category()});
}
mCurrentPosition = 0;
}
Expand Down Expand Up @@ -90,7 +78,7 @@ void StdIOCallback::setFilePointer(std::int64_t Offset,seek_mode Mode)
if(fseek(File,Offset,Mode)!=0) {
ostringstream Msg;
Msg<<"Failed to seek file "<<File<<" to offset "<<Offset<<" in mode "<<Mode;
throw CRTError(Msg.str());
throw ios_base::failure(Msg.str(), error_code{errno, std::system_category()});
}

switch ( Mode ) {
Expand Down Expand Up @@ -123,7 +111,7 @@ std::uint64_t StdIOCallback::getFilePointer()
if(Result<0) {
stringstream Msg;
Msg<<"Can't tell the current file pointer position for "<<File;
throw CRTError(Msg.str());
throw ios_base::failure(Msg.str(), error_code{errno, std::system_category()});
}
#endif

Expand All @@ -138,7 +126,7 @@ void StdIOCallback::close()
if(fclose(File)!=0) {
stringstream Msg;
Msg<<"Can't close file "<<File;
throw CRTError(Msg.str());
throw ios_base::failure(Msg.str(), error_code{errno, std::system_category()});
}

File=nullptr;
Expand Down