#ifndef EXCEPTION_H
#define EXCEPTION_H

/*
 * @(#)Exception.h
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 2002-2003 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDWserver.cpp for details.
 */

#include <stdarg.h>
#include <stdio.h>
#include "String.h"
#include "Log.h"

/**
 * The base class of all exceptions.
 *
 * @version 20030222
 * @author Jörg P. M. Haeger
 */
class Exception {
protected:
	String msg;
	String help;
public:
	Exception() {}

	Exception(const char *format, ...) {
		va_list ap;
		va_start(ap, format);
		char str[4 * 1024];
		vsnprintf(str, sizeof str, format, ap);
		va_end(ap);
		msg = str;
	}

	Exception(String &s): msg(s) {
		String::free(&s);
	}

	Exception *addHelp(const char *format, ...) {
		va_list ap;
		va_start(ap, format);
		char str[4 * 1024];
		vsnprintf(str, sizeof str, format, ap);
		va_end(ap);
		help = str;

		return this;
	}

	Exception *addHelp(String &s) {
		help = s;
		String::free(&s);
		return this;
	}

	const char *getHelp() {
		return help.getBytes();
	}

	String &getMessage() {
		return msg;
	}

	String &toString() {
		return msg;
	}
};

#endif
