/*********************************************************************************
 **
 ** Any exceptions to be thrown should be listed here.
 **
 *********************************************************************************/
#ifndef SMARTSAMPLER_EXCEPTIONS_HH
#define SMARTSAMPLER_EXCEPTIONS_HH

#include "Exception.h"
#include <string.h>

#define EXC_PREFIX "SmartSampler -- Exception!  "
#define MAX_MSG_LEN 128

// Start with a simple base class which just wraps the Exception constructor
class Exception_base : public Exception {
public:
  Exception_base(const char *msgIn):Exception(mkmsg(msgIn)){}
protected:
  char exc_msg[MAX_MSG_LEN];
  char *mkmsg(const char *msgIn){
    strcpy(exc_msg,EXC_PREFIX);
    if(strlen(exc_msg) + strlen(msgIn) > 126){
      // Just default to a std message
      return(strcat(exc_msg,"(Unknown cause)\n"));
    }
    return(strcat(strcat(exc_msg,msgIn),"\n"));
  }
};

#define EXC_LD_PREFIX "SmartSampler -- Load exception!  "
class LoadError :public Exception_base {
public:
  LoadError(const char *msgIn):Exception_base(msgIn){}
private:
  char exc_msg[MAX_MSG_LEN];
  char *mkmsg(const char *msgIn){
    strcpy(exc_msg,EXC_LD_PREFIX);
    if(strlen(exc_msg) + strlen(msgIn) > 126){
      // Just default to a std message
      return(strcat(exc_msg,"\n"));
    }
    return(strcat(strcat(exc_msg,msgIn),"\n"));
  }
}; // LoadError

#endif // SMARTSAMPLER_EXCEPTIONS_HH
