summaryrefslogtreecommitdiff
path: root/src/Exception.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Exception.cxx')
-rw-r--r--src/Exception.cxx59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Exception.cxx b/src/Exception.cxx
new file mode 100644
index 0000000..2d19769
--- /dev/null
+++ b/src/Exception.cxx
@@ -0,0 +1,59 @@
+namespace PluggIt {
+
+class Exception
+{
+ private string m_message;
+
+
+ public Exception( string message ) {
+ m_message = message;
+ }
+
+ public Exception( const char *format, ... ) D_FORMAT_PRINTF(2) {
+ va_list args;
+ int len;
+ char buf[200];
+ char *ptr = buf;
+
+ va_start( args, format );
+ len = vsnprintf( buf, sizeof(buf), format, args );
+ va_end( args );
+
+ if (len < 0)
+ abort();
+
+ if (len >= (int)sizeof(buf)) {
+ ptr = (char*) malloc( len+1 );
+ if (!ptr)
+ abort();
+
+ va_start( args, format );
+ len = vsnprintf( ptr, len+1, format, args );
+ va_end( args );
+
+ if (len < 0) {
+ free( ptr );
+ abort();
+ }
+ }
+
+ m_message = string( ptr );
+
+ if (ptr != buf)
+ free( ptr );
+ }
+
+ public string getMessage() {
+ return m_message;
+ }
+
+
+ friend std::ostream &operator << (std::ostream &stream, Exception *ex) {
+ stream << ex->getMessage();
+
+ return stream;
+ }
+};
+
+}
+