ShogunException.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2009 Soeren Sonnenburg
00008  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #include <shogun/lib/ShogunException.h>
00012 #include <shogun/lib/Signal.h>
00013 
00014 #include <string.h>
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 
00018 using namespace shogun;
00019 
00020 void
00021 ShogunException::init(const char* str)
00022 {
00023     size_t n = strlen(str) + 1;
00024 
00025     val = (char*) malloc(n);
00026     if (val)
00027         strncpy(val, str, n);
00028     else {
00029         fprintf(stderr, "Could not even allocate memory for exception"
00030                 " - dying.\n");
00031         exit(1);
00032     }
00033 }
00034 
00035 ShogunException::ShogunException(const char* str)
00036 {
00037 #ifndef WIN32
00038     CSignal::unset_handler();
00039 #endif
00040 
00041     init(str);
00042 }
00043 
00044 ShogunException::ShogunException(const ShogunException& orig)
00045 { init(orig.val); }
00046 
00047 ShogunException::~ShogunException() { free(val); }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation