00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PJ_EXCEPTION_H__
00021 #define __PJ_EXCEPTION_H__
00022
00028 #include <pj/types.h>
00029 #include <pj/compat/setjmp.h>
00030 #include <pj/log.h>
00031
00032
00033 PJ_BEGIN_DECL
00034
00035
00242 PJ_DECL(pj_status_t) pj_exception_id_alloc(const char *name,
00243 pj_exception_id_t *id);
00244
00252 PJ_DECL(pj_status_t) pj_exception_id_free(pj_exception_id_t id);
00253
00261 PJ_DECL(const char*) pj_exception_id_name(pj_exception_id_t id);
00262
00263
00266 #if defined(PJ_EXCEPTION_USE_WIN32_SEH) && PJ_EXCEPTION_USE_WIN32_SEH != 0
00267
00268
00269
00270
00271
00272 #define WIN32_LEAN_AND_MEAN
00273 #include <windows.h>
00274
00275 PJ_IDECL_NO_RETURN(void)
00276 pj_throw_exception_(pj_exception_id_t id) PJ_ATTR_NORETURN
00277 {
00278 RaiseException(id,1,0,NULL);
00279 }
00280
00281 #define PJ_USE_EXCEPTION
00282 #define PJ_TRY __try
00283 #define PJ_CATCH(id) __except(GetExceptionCode()==id ? \
00284 EXCEPTION_EXECUTE_HANDLER : \
00285 EXCEPTION_CONTINUE_SEARCH)
00286 #define PJ_CATCH_ANY __except(EXCEPTION_EXECUTE_HANDLER)
00287 #define PJ_END
00288 #define PJ_THROW(id) pj_throw_exception_(id)
00289 #define PJ_GET_EXCEPTION() GetExceptionCode()
00290
00291
00292 #elif defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 #ifdef __cplusplus
00303
00304 class TPjException
00305 {
00306 public:
00307 int code_;
00308 };
00309
00310 #define PJ_USE_EXCEPTION
00311 #define PJ_TRY try
00312
00313 #define PJ_CATCH_ANY catch (const TPjException & pj_excp_)
00314 #define PJ_END
00315 #define PJ_THROW(x_id) do { TPjException e; e.code_=x_id; throw e;} \
00316 while (0)
00317 #define PJ_GET_EXCEPTION() pj_excp_.code_
00318
00319 #else
00320
00321 #define PJ_USE_EXCEPTION
00322 #define PJ_TRY
00323 #define PJ_CATCH_ANY if (0)
00324 #define PJ_END
00325 #define PJ_THROW(x_id) do { PJ_LOG(1,("PJ_THROW"," error code = %d",x_id)); } while (0)
00326 #define PJ_GET_EXCEPTION() 0
00327
00328 #endif
00329
00330 #else
00331
00332
00333
00334
00335
00336
00341 struct pj_exception_state_t
00342 {
00343 struct pj_exception_state_t *prev;
00344 pj_jmp_buf state;
00345 };
00346
00351 PJ_DECL_NO_RETURN(void)
00352 pj_throw_exception_(pj_exception_id_t id) PJ_ATTR_NORETURN;
00353
00357 PJ_DECL(void) pj_push_exception_handler_(struct pj_exception_state_t *rec);
00358
00362 PJ_DECL(void) pj_pop_exception_handler_(struct pj_exception_state_t *rec);
00363
00368 #define PJ_USE_EXCEPTION struct pj_exception_state_t pj_x_except__; int pj_x_code__
00369
00374 #define PJ_TRY if (1) { \
00375 pj_push_exception_handler_(&pj_x_except__); \
00376 pj_x_code__ = pj_setjmp(pj_x_except__.state); \
00377 if (pj_x_code__ == 0)
00378
00383 #define PJ_CATCH(id) else if (pj_x_code__ == (id))
00384
00389 #define PJ_CATCH_ANY else
00390
00395 #define PJ_END pj_pop_exception_handler_(&pj_x_except__); \
00396 } else {}
00397
00403 #define PJ_THROW(exception_id) pj_throw_exception_(exception_id)
00404
00410 #define PJ_GET_EXCEPTION() (pj_x_code__)
00411
00412 #endif
00413
00414
00415 PJ_END_DECL
00416
00417
00418
00419 #endif
00420
00421