#ifndef ERROR_H
#define ERROR_H

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

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

class Throwable {
};

class Error: public Throwable {
	char str[4 * 1024], help[4 * 1024];

public:
	Error(const char *format, ...)
	{
		va_list ap;
		va_start(ap, format);
		vsprintf(str, format, ap);
		va_end(ap);

		help[0] = 0;
	}

	Error *addHelp(const char *format, ...)
	{
		va_list ap;
		va_start(ap, format);
		vsprintf(help, format, ap);
		va_end(ap);

		return this;
	}

	const char *getHelp()
	{
		return help;
	}

	const char *toString()
	{
		return str;
	}
};

class Exception: public Throwable {
	String msg;
public:
	Exception(const char *format, ...) {
		va_list ap;
		va_start(ap, format);
		char str[4 * 1024];
		vsprintf(str, format, ap);
		va_end(ap);
		msg = str;
	}

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

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

#endif
