map_exception.cpp

Go to the documentation of this file.
00001 /* ============================================================================
00002 The MapException class defines exceptions thrown by the skymap-related classes.
00003 
00004 Written by   Michael R. Greason, ADNET, 27 December 2006.
00005 Broken out of 'skymap.h'.  MRG, ADNET, 23 January 2007.
00006 ============================================================================ */
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include "map_exception.h"
00010 /* ----------------------------------------------------------------------------
00011 'MapException' is the class constructor.
00012 
00013 Arguments:
00014         code   - The error code.
00015         status - A status value associated with the exception.  Defaults to 0.
00016         comm   - A comment associated with the error.
00017 
00018 Returned:
00019         N/A.
00020 ---------------------------------------------------------------------------- */
00021 MapException::MapException (ErrCode code, int status, const char *comm)
00022 {
00023         code_    = code;
00024         status_  = status;
00025         comment_ = (comm == NULL) ? NULL : strdup(comm);
00026 }
00027 /* ----------------------------------------------------------------------------
00028 'MapException' is the class constructor.
00029 
00030 Arguments:
00031         code   - The error code.
00032         status - A status value associated with the exception.  Defaults to 0.
00033         
00034 
00035 Returned:
00036         N/A.
00037 ---------------------------------------------------------------------------- */
00038 MapException::~MapException (void)
00039 { 
00040         if (comment_ != NULL) delete [] comment_; 
00041 }
00042 /* ----------------------------------------------------------------------------
00043 'Message' returns an error message associated with the error code.
00044 
00045 Arguments:
00046         None.
00047 
00048 Returned:
00049         The error message.  This is written to internal static storage---be sure
00050         to do something with it before calling this function again.
00051 ---------------------------------------------------------------------------- */
00052 const char* MapException::Message (void) const
00053 {
00054         static char msg[48];
00055         switch (code_)
00056         {
00057                 case Memory:
00058                         strcpy(msg, "Memory allocation error!");
00059                         break;
00060                 case Bounds:
00061                         strcpy(msg, "Map index out of bounds!");
00062                         break;
00063                 case Undefined:
00064                         strcpy(msg, "Undefined pixel property!");
00065                         break;
00066                 case InvalidType:
00067                         strcpy(msg, "Invalid pixel type!");
00068                         break;
00069                 case FITSError:
00070                 if (status_ != 0) sprintf(msg, "FITS I/O Error:  %d", status_);
00071                                      else strcpy(msg, "FITS I/O Error");
00072                         break;
00073                 default:
00074                         *msg = '\0';
00075                         break;
00076         }
00077         return msg;
00078 }

Generated on Fri Feb 6 15:32:42 2009 for Skyviewer by  doxygen 1.4.7