Qucs-core  0.0.19
exception.cpp
Go to the documentation of this file.
00001 /*
00002  * exception.cpp - exception class implementation
00003  *
00004  * Copyright (C) 2004 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  * 
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.  
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <stdarg.h>
00033 
00034 #include "exception.h"
00035 
00036 using namespace qucs;
00037 
00038 // Constructor creates an instance of the exception class.
00039 exception::exception () {
00040   code = EXCEPTION_UNKNOWN;
00041   txt = NULL;
00042   data = 0;
00043 }
00044 
00045 // Constructor creates an typified instance of the exception class.
00046 exception::exception (int type) {
00047   code = type;
00048   txt = NULL;
00049   data = 0;
00050 }
00051 
00052 /* This copy constructor creates a instance of the exception class based
00053    on the given exception. */
00054 exception::exception (const exception & e) {
00055   txt = e.txt ? strdup (e.txt) : NULL;
00056   code = e.code;
00057   data = e.data;
00058 }
00059 
00060 // Destructor deletes an instance of the exception class.
00061 exception::~exception () {
00062   free (txt);
00063 }
00064 
00065 /* This function save the given messages format and the appropriate
00066    arguments to the internal text property of the exception object. */
00067 void exception::setText (const char * format, ...) {
00068   char * str;
00069   va_list args;
00070 
00071   free (txt);
00072   str = (char *) malloc (1024); // this should be enough
00073   va_start (args, format);
00074   vsprintf (str, format, args);
00075   va_end (args);
00076 
00077   // copy string to text buffer
00078   txt = strdup (str); free (str);
00079 }