00001 /* 00002 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00003 May be copied only for purposes and under conditions described 00004 on the Web page www.basepath.com/aup/copyright.htm. 00005 00006 The Example Files are provided "as is," without any warranty; 00007 without even the implied warranty of merchantability or fitness 00008 for a particular purpose. The author and his publisher are not 00009 responsible for any damages, direct or incidental, resulting 00010 from the use or non-use of these Example Files. 00011 00012 The Example Files may contain defects, and some contain deliberate 00013 coding mistakes that were included for educational reasons. 00014 You are responsible for determining if and how the Example Files 00015 are to be used. 00016 00017 */ 00018 #include "ux.hpp" 00019 #ifdef SOLARIS 00020 #define __EXTENSIONS__ 00021 #endif 00022 #include <netdb.h> // for gai_strerror 00023 00024 using namespace Ux; 00025 00026 /** 00027 Stream operator to output Error. 00028 */ 00029 std::ostream& Ux::operator<<(std::ostream& s, const Error& e) 00030 { 00031 s << "[ERROR: " << (const char *)e << "]"; 00032 return s; 00033 } 00034 00035 /** 00036 Required what function for subclasses of exception. 00037 */ 00038 const char* Error::what() const throw() 00039 { 00040 switch (get_type()) { 00041 case EC_EAI: 00042 return gai_strerror(get_code()); 00043 case EC_ERRNO: 00044 return strerror(get_code()); 00045 case EC_GETDATE: 00046 return getdate_strerror(get_code()); // AUP2 fcn -- not a std. fcn. 00047 default: 00048 return "[No error]"; 00049 } 00050 }