root/src/gauche/exception.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ScmMessageCondition
  2. ScmSystemError
  3. ScmReadError
  4. ScmPortError
  5. ScmCompoundCondition
  6. ScmApplicationExit
  7. ScmThreadException

   1 /*
   2  * exception.h - more exception classes
   3  *
   4  *   Copyright (c) 2000-2004 Shiro Kawai, All rights reserved.
   5  * 
   6  *   Redistribution and use in source and binary forms, with or without
   7  *   modification, are permitted provided that the following conditions
   8  *   are met:
   9  * 
  10  *   1. Redistributions of source code must retain the above copyright
  11  *      notice, this list of conditions and the following disclaimer.
  12  *
  13  *   2. Redistributions in binary form must reproduce the above copyright
  14  *      notice, this list of conditions and the following disclaimer in the
  15  *      documentation and/or other materials provided with the distribution.
  16  *
  17  *   3. Neither the name of the authors nor the names of its contributors
  18  *      may be used to endorse or promote products derived from this
  19  *      software without specific prior written permission.
  20  *
  21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  27  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  *
  33  *  $Id: exception.h,v 1.11 2004/11/23 13:10:00 shirok Exp $
  34  */
  35 
  36 #ifndef GAUCHE_EXCEPTION_H
  37 #define GAUCHE_EXCEPTION_H
  38 
  39 /* Condition class hierarchy
  40  
  41   <condition> ; srfi-35
  42     +- <compound-condition>
  43     +- <serious-condition> ; srfi-35
  44     |    +- <serious-compound-condition> ; also inherits <compound-condition>
  45     +- <message-condition> ; srfi-35
  46     |    +- <application-exit>           ; also inherits <serious-condition>
  47     |    +- <error>             ; srfi-35, also inherits <serious-condition>
  48     |         +- <system-error>
  49     |         +- <read-error> ; srfi-36
  50     |         +- <io-error>   ; srfi-36
  51     |              +- <port-error> ; srfi-36
  52     |              |    +- <io-read-error>   ; srfi-36
  53     |              |    +- <io-write-error>  ; srfi-36
  54     |              |    +- <io-closed-error> ; srfi-36
  55     |              |    +- <io-unit-error>
  56     |              +- <filename-error> ; srfi-36 (*)
  57     |                   +- <malformed-filename-error>  ; srfi-36 (*)
  58     |                   +- <file-protection-error>     ; srfi-36 (*)
  59     |                   |    +- <file-is-read-only-error> ; srfi-36 (*)
  60     |                   +- <file-already-exists-error> ; srfi-36 (*)
  61     |                   +- <no-such-file-error>        ; srfi-36 (*)
  62     +- <thread-exception> ; srfi-18
  63          +- <join-timeout-exception>      ; srfi-18
  64          +- <abandoned-mutex-exception>   ; srfi-18
  65          +- <terminated-thread-exception> ; srfi-18
  66          +- <uncaught-exception>          ; srfi-18
  67 
  68  (*) - not implemented yet
  69 */
  70 
  71 /*---------------------------------------------------
  72  * Base conditions.
  73  */
  74 
  75 /* <condition> : root of all condition types. */
  76 typedef ScmInstance ScmCondition;
  77 
  78 SCM_CLASS_DECL(Scm_ConditionClass);
  79 #define SCM_CLASS_CONDITION        (&Scm_ConditionClass)
  80 #define SCM_CONDITIONP(obj)        SCM_ISA(obj, SCM_CLASS_CONDITION)
  81 
  82 SCM_EXTERN int Scm_ConditionHasType(ScmObj c, ScmObj k);
  83 
  84 /* <message-condition> : condition with message. */
  85 typedef struct ScmMessageConditionRec {
  86     ScmCondition common;
  87     ScmObj message;             /* message */
  88 } ScmMessageCondition;
  89 
  90 SCM_CLASS_DECL(Scm_MessageConditionClass);
  91 #define SCM_CLASS_MESSAGE_CONDITION  (&Scm_MessageConditionClass)
  92 #define SCM_MESSAGE_CONDITION_P(obj) SCM_ISA(obj, SCM_CLASS_MESSAGE_CONDITION)
  93 #define SCM_MESSAGE_CONDITION(obj)   ((ScmMessageCondition*)(obj))
  94 
  95 /* <serious-condition> : condition which can't be restarted */
  96 typedef ScmCondition ScmSeriousCondition;
  97 
  98 SCM_CLASS_DECL(Scm_SeriousConditionClass);
  99 #define SCM_CLASS_SERIOUS_CONDITION  (&Scm_SeriousConditionClass)
 100 #define SCM_SERIOUS_CONDITION_P(obj) SCM_ISA(obj, SCM_CLASS_SERIOUS_CONDITION)
 101 #define SCM_SERIOUS_CONDITION(obj)   ((ScmSeriousCondition*)(obj))
 102 
 103 /*---------------------------------------------------
 104  * Errors
 105  */
 106 
 107 /* <error>: root of all errors. */
 108 typedef ScmMessageCondition ScmError;
 109 
 110 SCM_CLASS_DECL(Scm_ErrorClass);
 111 #define SCM_CLASS_ERROR            (&Scm_ErrorClass)
 112 #define SCM_ERRORP(obj)            SCM_ISA(obj, SCM_CLASS_ERROR)
 113 #define SCM_ERROR(obj)             ((ScmError*)(obj))
 114 #define SCM_ERROR_MESSAGE(obj)     SCM_ERROR(obj)->message
 115 
 116 SCM_EXTERN ScmObj Scm_MakeError(ScmObj message);
 117 
 118 /* <system-error>: error from system calls */
 119 typedef struct ScmSystemErrorRec {
 120     ScmError common;
 121     int error_number;           /* errno */
 122 } ScmSystemError;
 123     
 124 SCM_CLASS_DECL(Scm_SystemErrorClass);
 125 #define SCM_CLASS_SYSTEM_ERROR     (&Scm_SystemErrorClass)
 126 #define SCM_SYSTEM_ERROR(obj)      ((ScmSystemError*)(obj))
 127 #define SCM_SYSTEM_ERROR_P(obj)    SCM_ISA(obj, SCM_CLASS_SYSTEM_ERROR)
 128 
 129 SCM_EXTERN ScmObj Scm_MakeSystemError(ScmObj message, int error_num);
 130 
 131 /* <read-error>: error from the reader */
 132 typedef struct ScmReadErrorRec {
 133     ScmError common;
 134     ScmPort *port;              /* input port where we're reading from. */
 135     int line;                   /* line number (if available), or -1 */
 136 } ScmReadError;
 137 
 138 SCM_CLASS_DECL(Scm_ReadErrorClass);
 139 #define SCM_CLASS_READ_ERROR     (&Scm_ReadErrorClass)
 140 #define SCM_READ_ERROR(obj)      ((ScmReadError*)(obj))
 141 #define SCM_READ_ERROR_P(obj)    SCM_ISA(obj, SCM_CLASS_READ_ERROR)
 142 
 143 SCM_EXTERN ScmObj Scm_MakeReadError(ScmObj message, ScmPort *p, int line);
 144 
 145 /* <io-error>: abstract class for I/O related error. */
 146 typedef ScmError ScmIOError;
 147 
 148 SCM_CLASS_DECL(Scm_IOErrorClass);
 149 #define SCM_CLASS_IO_ERROR       (&Scm_IOErrorClass)
 150 #define SCM_IO_ERROR_P(obj)      SCM_ISA(obj, SCM_CLASS_IO_ERROR)
 151 
 152 /* <port-error>: Port related error, inherits <io-error> */
 153 typedef struct ScmPortErrorRec {
 154     ScmIOError common;
 155     ScmPort *port;              /* The port where I/O error occurs */
 156 } ScmPortError;
 157 
 158 SCM_CLASS_DECL(Scm_PortErrorClass);
 159 #define SCM_CLASS_PORT_ERROR     (&Scm_PortErrorClass)
 160 #define SCM_PORT_ERROR(obj)      ((ScmPortError*)(obj))
 161 #define SCM_PORT_ERROR_P(obj)    SCM_ISA(obj, SCM_CLASS_PORT_ERROR)
 162 
 163 /* <io-read-error>, <io-write-error>, <io-closed-error> :
 164    subclasses of port-error */
 165 
 166 typedef ScmPortError ScmIOReadError;
 167 typedef ScmPortError ScmIOWriteError;
 168 typedef ScmPortError ScmIOClosedError;
 169 typedef ScmPortError ScmIOUnitError;
 170 
 171 SCM_CLASS_DECL(Scm_IOReadErrorClass);
 172 #define SCM_CLASS_IO_READ_ERROR      (&Scm_IOReadErrorClass)
 173 SCM_CLASS_DECL(Scm_IOWriteErrorClass);
 174 #define SCM_CLASS_IO_WRITE_ERROR     (&Scm_IOWriteErrorClass)
 175 SCM_CLASS_DECL(Scm_IOClosedErrorClass);
 176 #define SCM_CLASS_IO_CLOSED_ERROR    (&Scm_IOClosedErrorClass)
 177 SCM_CLASS_DECL(Scm_IOUnitErrorClass);
 178 #define SCM_CLASS_IO_UNIT_ERROR      (&Scm_IOUnitErrorClass)
 179 
 180 /*---------------------------------------------------
 181  * Compounders
 182  */
 183 
 184 /* compound condition may automatically be an instance of
 185    <serious-compound-condition> if any of its component
 186    exception is an instance of <serious-condition>.
 187 
 188    Compound condition never 'nests', i.e. any member of conditions
 189    isn't a compound condition itself. */
 190 
 191 typedef struct ScmCompoundConditionRec {
 192     ScmCondition common;
 193     ScmObj conditions;          /* list of simple conditions */
 194 } ScmCompoundCondition;
 195 
 196 SCM_CLASS_DECL(Scm_CompoundConditionClass);
 197 #define SCM_CLASS_COMPOUND_CONDITION   (&Scm_CompoundConditionClass)
 198 #define SCM_COMPOUND_CONDITION(obj)    ((ScmCompoundCondition*)(obj))
 199 #define SCM_COMPOUND_CONDITION_P(obj)  SCM_ISA(obj, SCM_CLASS_COMPOUND_CONDITION)
 200 
 201 SCM_CLASS_DECL(Scm_SeriousCompoundConditionClass);
 202 #define SCM_CLASS_SERIOUS_COMPOUND_CONDITION (&Scm_SeriousCompoundConditionClass)
 203 #define SCM_SERIOUS_COMPOUND_CONDITION_P(obj) SCM_ISA(obj, SCM_CLASS_SERIOUS_COMPOUND_CONDITION)
 204 
 205 SCM_EXTERN ScmObj Scm_MakeCompoundCondition(ScmObj conditions);
 206 
 207 /*---------------------------------------------------
 208  * Application exit
 209  */
 210 
 211 /* <application-exit> */
 212 typedef struct ScmApplicationExitRec {
 213     ScmMessageCondition common;
 214     int  code;                  /* exit code */
 215 } ScmApplicationExit;
 216 
 217 SCM_CLASS_DECL(Scm_ApplicationExitClass);
 218 #define SCM_CLASS_APPLICATION_EXIT   (&Scm_ApplicationExitClass)
 219 #define SCM_APPLICATION_EXIT_P(obj)  SCM_ISA(obj, SCM_CLASS_APPLICATION_EXIT)
 220 
 221 SCM_EXTERN ScmObj Scm_MakeApplicationExit(int);
 222 
 223 /*---------------------------------------------------
 224  * Thread exceptions
 225  */
 226 
 227 typedef struct ScmThreadExceptionRec {
 228     SCM_HEADER;
 229     ScmVM *thread;              /* the thread that caused the exception */
 230     ScmObj data;                /* additional data.
 231                                    <join-timeout-exception> : n/a
 232                                    <abandoned-mutex-exception> : mutex
 233                                    <terminated-thread-exception> : n/a
 234                                    <uncaught-exception> : exception
 235                                 */
 236 } ScmThreadException;
 237 
 238 SCM_CLASS_DECL(Scm_ThreadExceptionClass);
 239 #define SCM_CLASS_THREAD_EXCEPTION  (&Scm_ThreadExceptionClass)
 240 #define SCM_THREAD_EXCEPTION_P(obj) SCM_ISA(obj, SCM_CLASS_THREAD_EXCEPTION)
 241 #define SCM_THREAD_EXCEPTION(obj)   ((ScmThreadException*)(obj))
 242 
 243 SCM_CLASS_DECL(Scm_JoinTimeoutExceptionClass);
 244 #define SCM_CLASS_JOIN_TIMEOUT_EXCEPTION (&Scm_JoinTimeoutExceptionClass)
 245 #define SCM_JOIN_TIMEOUT_EXCEPTION_P     SCM_ISA(obj, SCM_CLASS_JOIN_TIMEOUT_EXCEPTION)
 246 
 247 SCM_CLASS_DECL(Scm_AbandonedMutexExceptionClass);
 248 #define SCM_CLASS_ABANDONED_MUTEX_EXCEPTION (&Scm_AbandonedMutexExceptionClass)
 249 #define SCM_ABANDONED_MUTEX_EXCEPTION_P     SCM_ISA(obj, SCM_CLASS_ABANDONED_MUTEX_EXCEPTION)
 250 
 251 SCM_CLASS_DECL(Scm_TerminatedThreadExceptionClass);
 252 #define SCM_CLASS_TERMINATED_THREAD_EXCEPTION (&Scm_TerminatedThreadExceptionClass)
 253 #define SCM_TERMINATED_THREAD_EXCEPTION_P     SCM_ISA(obj, SCM_CLASS_TERMINATED_THREAD_EXCEPTION)
 254 
 255 SCM_CLASS_DECL(Scm_UncaughtExceptionClass);
 256 #define SCM_CLASS_UNCAUGHT_EXCEPTION (&Scm_UncaughtExceptionClass)
 257 #define SCM_UNCAUGHT_EXCEPTION_P     SCM_ISA(obj, SCM_CLASS_UNCAUGHT_EXCEPTION)
 258 
 259 SCM_EXTERN ScmObj Scm_MakeThreadException(ScmClass*, ScmVM*);
 260 
 261 #endif /*GAUCHE_EXCEPTION_H*/

/* [<][>][^][v][top][bottom][index][help] */