From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: [PATCH kvm-unit-tests v2 03/14] Add exception class for kernel errors (errno) Date: Wed, 15 Dec 2010 18:09:32 +0200 Message-ID: <1292429383-15326-4-git-send-email-avi@redhat.com> References: <1292429383-15326-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:18392 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751661Ab0LOQKG (ORCPT ); Wed, 15 Dec 2010 11:10:06 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBFGA5lL003455 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 15 Dec 2010 11:10:06 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBFGA5Rs019585 for ; Wed, 15 Dec 2010 11:10:05 -0500 In-Reply-To: <1292429383-15326-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Signed-off-by: Avi Kivity --- api/exception.cc | 20 ++++++++++++++++++++ api/exception.hh | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) create mode 100644 api/exception.cc create mode 100644 api/exception.hh diff --git a/api/exception.cc b/api/exception.cc new file mode 100644 index 0000000..500569a --- /dev/null +++ b/api/exception.cc @@ -0,0 +1,20 @@ +#include "exception.hh" +#include +#include + +errno_exception::errno_exception(int errno) + : _errno(errno) +{ +} + +int errno_exception::errno() const +{ + return _errno; +} + +const char *errno_exception::what() +{ + std::snprintf(_buf, sizeof _buf, "error: %s (%d)", + std::strerror(_errno), _errno); + return _buf; +} diff --git a/api/exception.hh b/api/exception.hh new file mode 100644 index 0000000..4672760 --- /dev/null +++ b/api/exception.hh @@ -0,0 +1,16 @@ +#ifndef EXCEPTION_HH +#define EXCEPTION_HH + +#include + +class errno_exception : public std::exception { +public: + explicit errno_exception(int err_no); + int errno() const; + virtual const char *what(); +private: + int _errno; + char _buf[1000]; +}; + +#endif -- 1.7.1