00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00021 #ifndef FALCON_ERROR_H
00022 #define FALCON_ERROR_H
00023
00024 #include <falcon/setup.h>
00025 #include <falcon/types.h>
00026 #include <falcon/item.h>
00027 #include <falcon/genericlist.h>
00028 #include <falcon/string.h>
00029 #include <falcon/crobject.h>
00030 #include <falcon/reflectfunc.h>
00031
00032 namespace Falcon {
00033
00034 class Error;
00035
00036 namespace core {
00037 FALCON_FUNC_DYN_SYM Error_init ( ::Falcon::VMachine *vm );
00038 FALCON_FUNC_DYN_SYM SyntaxError_init ( ::Falcon::VMachine *vm );
00039 FALCON_FUNC_DYN_SYM CodeError_init ( ::Falcon::VMachine *vm );
00040 FALCON_FUNC_DYN_SYM IoError_init ( ::Falcon::VMachine *vm );
00041 FALCON_FUNC_DYN_SYM AccessError_init ( ::Falcon::VMachine *vm );
00042 FALCON_FUNC_DYN_SYM MathError_init ( ::Falcon::VMachine *vm );
00043 FALCON_FUNC_DYN_SYM ParamError_init ( ::Falcon::VMachine *vm );
00044 FALCON_FUNC_DYN_SYM ParseError_init ( ::Falcon::VMachine *vm );
00045
00047 extern reflectionFuncDecl Error_code_rfrom;
00048 extern reflectionFuncDecl Error_description_rfrom;
00049 extern reflectionFuncDecl Error_message_rfrom;
00050 extern reflectionFuncDecl Error_systemError_rfrom;
00051 extern reflectionFuncDecl Error_origin_rfrom;
00052 extern reflectionFuncDecl Error_module_rfrom;
00053 extern reflectionFuncDecl Error_symbol_rfrom;
00054 extern reflectionFuncDecl Error_line_rfrom;
00055 extern reflectionFuncDecl Error_pc_rfrom;
00056 extern reflectionFuncDecl Error_subErrors_rfrom;
00057
00058 extern reflectionFuncDecl Error_code_rto;
00059 extern reflectionFuncDecl Error_description_rto;
00060 extern reflectionFuncDecl Error_message_rto;
00061 extern reflectionFuncDecl Error_systemError_rto;
00062 extern reflectionFuncDecl Error_origin_rto;
00063 extern reflectionFuncDecl Error_module_rto;
00064 extern reflectionFuncDecl Error_symbol_rto;
00065 extern reflectionFuncDecl Error_line_rto;
00066 extern reflectionFuncDecl Error_pc_rto;
00067
00069 class ErrorObject: public CRObject
00070 {
00071 public:
00072 ErrorObject( const CoreClass* cls, Error *err );
00073 Error* getError() const { return (::Falcon::Error*) getUserData(); }
00074
00075 virtual ~ErrorObject();
00076 virtual void gcMark( uint32 mark );
00077 virtual CoreObject *clone() const;
00078 };
00079
00080 CoreObject* ErrorObjectFactory( const CoreClass *cls, void *user_data, bool bDeserial );
00081 }
00082
00083
00084
00085 #include <falcon/eng_messages.h>
00086
00087
00088 #define FLC_DECLARE_ERROR_TABLE
00089 #include <falcon/eng_messages.h>
00090 #undef FLC_DECLARE_ERROR_TABLE
00091
00092 typedef enum {
00093 e_orig_compiler = 1,
00094 e_orig_assembler = 2,
00095 e_orig_loader = 3,
00096 e_orig_vm = 4,
00097 e_orig_script = 5,
00098 e_orig_runtime = 9,
00099 e_orig_mod = 10
00100 } t_origin;
00101
00102 class FALCON_DYN_CLASS TraceStep: public BaseAlloc
00103 {
00104 String m_module;
00105 String m_symbol;
00106 uint32 m_line;
00107 uint32 m_pc;
00108
00109 public:
00110 TraceStep( const String &module, const String symbol, uint32 line, uint32 pc ):
00111 m_module( module ),
00112 m_symbol( symbol ),
00113 m_line( line ),
00114 m_pc( pc )
00115 {}
00116
00117 const String &module() const { return m_module; }
00118 const String &symbol() const { return m_symbol; }
00119 uint32 line() const { return m_line; }
00120 uint32 pcounter() const { return m_pc; }
00121
00122 String toString() const { String temp; return toString( temp ); }
00123 String &toString( String &target ) const;
00124 };
00125
00144 class ErrorParam: public BaseAlloc
00145 {
00146
00147 public:
00148
00156 ErrorParam( int code, uint32 line = 0 ):
00157 m_errorCode( code ),
00158 m_line( line ),
00159 m_character( 0 ),
00160 m_pc( 0 ),
00161 m_sysError( 0 ),
00162 m_origin( e_orig_mod ),
00163 m_catchable( true )
00164 {}
00165
00166 ErrorParam &code( int code ) { m_errorCode = code; return *this; }
00167 ErrorParam &desc( const String &d ) { m_description = d; return *this; }
00168 ErrorParam &extra( const String &e ) { m_extra = e; return *this; }
00169 ErrorParam &symbol( const String &sym ) { m_symbol = sym; return *this; }
00170 ErrorParam &module( const String &mod ) { m_module = mod; return *this; }
00171 ErrorParam &line( uint32 line ) { m_line = line; return *this; }
00172 ErrorParam &pc( uint32 pc ) { m_pc = pc; return *this; }
00173 ErrorParam &sysError( uint32 e ) { m_sysError = e; return *this; }
00174 ErrorParam &chr( uint32 c ) { m_character = c; return *this; }
00175 ErrorParam &origin( t_origin orig ) { m_origin = orig; return *this; }
00176 ErrorParam &hard() { m_catchable = false; return *this; }
00177
00178 private:
00179 friend class Error;
00180
00181 int m_errorCode;
00182 String m_description;
00183 String m_extra;
00184 String m_symbol;
00185 String m_module;
00186
00187 uint32 m_line;
00188 uint32 m_character;
00189 uint32 m_pc;
00190 uint32 m_sysError;
00191
00192 t_origin m_origin;
00193 bool m_catchable;
00194 };
00195
00226 class FALCON_DYN_CLASS Error: public BaseAlloc
00227 {
00228 protected:
00229 int32 m_refCount;
00230
00231 int m_errorCode;
00232 String m_description;
00233 String m_extra;
00234 String m_symbol;
00235 String m_module;
00236 String m_className;
00237
00238 uint32 m_line;
00239 uint32 m_character;
00240 uint32 m_pc;
00241 uint32 m_sysError;
00242
00243 t_origin m_origin;
00244 bool m_catchable;
00245 Item m_raised;
00246
00247 List m_steps;
00248 ListElement *m_stepIter;
00249
00250 Error *m_nextError;
00251 Error *m_LastNextError;
00252
00256 Error( const String &className ):
00257 m_refCount( 1 ),
00258 m_errorCode ( e_none ),
00259 m_className( className ),
00260 m_line( 0 ),
00261 m_character( 0 ),
00262 m_pc( 0 ),
00263 m_sysError( 0 ),
00264 m_origin( e_orig_runtime ),
00265 m_catchable( true ),
00266 m_nextError( 0 ),
00267 m_LastNextError( 0 )
00268 {
00269 m_raised.setNil();
00270 }
00271
00273 Error( const Error &e );
00274
00279 Error( const String &className, const ErrorParam ¶ms ):
00280 m_refCount( 1 ),
00281 m_errorCode ( params.m_errorCode ),
00282 m_description( params.m_description ),
00283 m_extra( params.m_extra ),
00284 m_symbol( params.m_symbol ),
00285 m_module( params.m_module ),
00286 m_className( className ),
00287 m_line( params.m_line ),
00288 m_character( params.m_character ),
00289 m_pc( params.m_pc ),
00290 m_sysError( params.m_sysError ),
00291 m_origin( params.m_origin ),
00292 m_catchable( params.m_catchable ),
00293 m_nextError( 0 ),
00294 m_LastNextError( 0 )
00295 {
00296 m_raised.setNil();
00297 }
00298
00302 virtual ~Error();
00303 public:
00304
00305 Error():
00306 m_refCount( 1 ),
00307 m_errorCode ( e_none ),
00308 m_className( "Error" ),
00309 m_line( 0 ),
00310 m_character( 0 ),
00311 m_pc( 0 ),
00312 m_sysError( 0 ),
00313 m_origin( e_orig_runtime ),
00314 m_catchable( true ),
00315 m_nextError( 0 ),
00316 m_LastNextError( 0 )
00317 {
00318 m_raised.setNil();
00319 }
00320
00321 Error( const ErrorParam ¶ms ):
00322 m_refCount( 1 ),
00323 m_errorCode ( params.m_errorCode ),
00324 m_description( params.m_description ),
00325 m_extra( params.m_extra ),
00326 m_symbol( params.m_symbol ),
00327 m_module( params.m_module ),
00328 m_className( "Error" ),
00329 m_line( params.m_line ),
00330 m_character( params.m_character ),
00331 m_pc( params.m_pc ),
00332 m_sysError( params.m_sysError ),
00333 m_origin( params.m_origin ),
00334 m_catchable( params.m_catchable ),
00335 m_nextError( 0 ),
00336 m_LastNextError( 0 )
00337 {
00338 m_raised.setNil();
00339 }
00340
00341 void errorCode( int ecode ) { m_errorCode = ecode; }
00342 void systemError( uint32 ecode ) { m_sysError = ecode; }
00343 void errorDescription( const String &errorDesc ) { m_description = errorDesc; }
00344 void extraDescription( const String &extra ) { m_extra = extra; }
00345 void module( const String &moduleName ) { m_module = moduleName; }
00346 void symbol( const String &symbolName ) { m_symbol = symbolName; }
00347 void line( uint32 line ) { m_line = line; }
00348 void character( uint32 chr ) { m_character = chr; }
00349 void pcounter( uint32 pc ) { m_pc = pc; }
00350 void origin( t_origin o ) { m_origin = o; }
00351 void catchable( bool c ) { m_catchable = c; }
00352 void raised( const Item &itm ) { m_raised = itm; }
00353
00354 int errorCode() const { return m_errorCode; }
00355 uint32 systemError() const { return m_sysError; }
00356 const String &errorDescription() const { return m_description; }
00357 const String &extraDescription() const { return m_extra; }
00358 const String &module() const { return m_module; }
00359 const String &symbol() const { return m_symbol; }
00360 uint32 line() const { return m_line; }
00361 uint32 character() const { return m_character; }
00362 uint32 pcounter() const { return m_pc; }
00363 t_origin origin() const { return m_origin; }
00364 bool catchable() const { return m_catchable; }
00365 const Item &raised() const { return m_raised; }
00366
00367 String toString() const { String temp; return toString( temp ); }
00368 virtual String &toString( String &target ) const;
00369
00377 virtual String &heading( String &target ) const;
00378
00379
00380 void appendSubError( Error *sub );
00381
00399 virtual CoreObject *scriptize( VMachine *vm );
00400
00401 void addTrace( const String &module, const String &symbol, uint32 line, uint32 pc );
00402 bool nextStep( String &module, String &symbol, uint32 &line, uint32 &pc );
00403 void rewindStep();
00404
00405 const String &className() const { return m_className; }
00406
00407 void incref();
00408 void decref();
00409
00410 Error* subError() const { return m_nextError; }
00411
00412 virtual Error *clone() const;
00413
00414 bool hasTraceback() const { return ! m_steps.empty(); }
00415 };
00416
00417
00418
00419 class GenericError: public Error
00420 {
00421 public:
00422 GenericError():
00423 Error( "GenericError" )
00424 {}
00425
00426 GenericError( const ErrorParam ¶ms ):
00427 Error( "GenericError", params )
00428 {}
00429 };
00430
00431 class CodeError: public Error
00432 {
00433 public:
00434 CodeError():
00435 Error( "CodeError" )
00436 {}
00437
00438 CodeError( const ErrorParam ¶ms ):
00439 Error( "CodeError", params )
00440 {}
00441 };
00442
00443 class SyntaxError: public Error
00444 {
00445 public:
00446 SyntaxError():
00447 Error( "SyntaxError" )
00448 {}
00449
00450 SyntaxError( const ErrorParam ¶ms ):
00451 Error( "SyntaxError", params )
00452 {}
00453 };
00454
00455 class AccessError: public Error
00456 {
00457 public:
00458 AccessError():
00459 Error( "AccessError" )
00460 {}
00461
00462 AccessError( const ErrorParam ¶ms ):
00463 Error( "AccessError", params )
00464 {}
00465 };
00466
00467 class MathError: public Error
00468 {
00469 public:
00470 MathError():
00471 Error( "MathError" )
00472 {}
00473
00474 MathError( const ErrorParam ¶ms ):
00475 Error( "MathError", params )
00476 {}
00477 };
00478
00479 class TypeError: public Error
00480 {
00481 public:
00482 TypeError():
00483 Error( "TypeError" )
00484 {}
00485
00486 TypeError( const ErrorParam ¶ms ):
00487 Error( "TypeError", params )
00488 {}
00489 };
00490
00491 class IoError: public Error
00492 {
00493 public:
00494 IoError():
00495 Error( "IoError" )
00496 {}
00497
00498 IoError( const ErrorParam ¶ms ):
00499 Error( "IoError", params )
00500 {}
00501 };
00502
00503
00504 class ParamError: public Error
00505 {
00506 public:
00507 ParamError():
00508 Error( "ParamError" )
00509 {}
00510
00511 ParamError( const ErrorParam ¶ms ):
00512 Error( "ParamError", params )
00513 {}
00514 };
00515
00516 class ParseError: public Error
00517 {
00518 public:
00519 ParseError():
00520 Error( "ParseError" )
00521 {}
00522
00523 ParseError( const ErrorParam ¶ms ):
00524 Error( "ParseError", params )
00525 {}
00526 };
00527
00528 class CloneError: public Error
00529 {
00530 public:
00531 CloneError():
00532 Error( "CloneError" )
00533 {}
00534
00535 CloneError( const ErrorParam ¶ms ):
00536 Error( "CloneError", params )
00537 {}
00538 };
00539
00540 class InterruptedError: public Error
00541 {
00542 public:
00543 InterruptedError():
00544 Error( "InterruptedError" )
00545 {}
00546
00547 InterruptedError( const ErrorParam ¶ms ):
00548 Error( "InterruptedError", params )
00549 {}
00550 };
00551
00552 class MessageError: public Error
00553 {
00554 public:
00555 MessageError():
00556 Error( "MessageError" )
00557 {}
00558
00559 MessageError( const ErrorParam ¶ms ):
00560 Error( "MessageError", params )
00561 {}
00562 };
00563
00564 class TableError: public Error
00565 {
00566 public:
00567 TableError():
00568 Error( "TableError" )
00569 {}
00570
00571 TableError( const ErrorParam ¶ms ):
00572 Error( "TableError", params )
00573 {}
00574 };
00575
00576
00580 const String &errorDesc( int errorCode );
00581
00582
00583 }
00584
00585 #endif
00586
00587