Skip to content

Commit

Permalink
Add line info to serious exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Feb 24, 2017
1 parent d2c79bf commit 7a24a57
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions libdevcore/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct Exception: virtual std::exception, virtual boost::exception
Exception(std::string _message = std::string()): m_message(std::move(_message)) {}
const char* what() const noexcept override { return m_message.empty() ? std::exception::what() : m_message.c_str(); }

/// @returns "FileName:LineNumber" referring to the point where the exception was thrown.
std::string lineInfo() const;

private:
std::string m_message;
};
Expand Down
14 changes: 14 additions & 0 deletions libsolidity/interface/Exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <libsolidity/interface/Exceptions.h>
#include <libsolidity/interface/Utils.h>

using namespace std;
using namespace dev;
using namespace dev::solidity;

Expand Down Expand Up @@ -56,3 +57,16 @@ Error::Error(Type _type): m_type(_type)
break;
}
}

string Exception::lineInfo() const
{
char const* const* file = boost::get_error_info<boost::throw_file>(*this);
int const* line = boost::get_error_info<boost::throw_line>(*this);
string ret;
if (file)
ret += *file;
ret += ':';
if (line)
ret += boost::lexical_cast<string>(*line);
return ret;
}
6 changes: 3 additions & 3 deletions solc/jsonCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
}
catch (CompilerError const& exception)
{
errors.append(formatError(exception, "Compiler error", scannerFromSourceName));
errors.append(formatError(exception, "Compiler error (" + exception.lineInfo() + ")", scannerFromSourceName));
}
catch (InternalCompilerError const& exception)
{
errors.append(formatError(exception, "Internal compiler error", scannerFromSourceName));
errors.append(formatError(exception, "Internal compiler error (" + exception.lineInfo() + ")", scannerFromSourceName));
}
catch (UnimplementedFeatureError const& exception)
{
errors.append(formatError(exception, "Unimplemented feature", scannerFromSourceName));
errors.append(formatError(exception, "Unimplemented feature (" + exception.lineInfo() + ")", scannerFromSourceName));
}
catch (Exception const& exception)
{
Expand Down

0 comments on commit 7a24a57

Please sign in to comment.