BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

except.h
Go to the documentation of this file.
1 /* $Id: except.h 4537 2013-06-19 06:47:43Z riza $ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 #ifndef __PJ_EXCEPTION_H__
21 #define __PJ_EXCEPTION_H__
22 
28 #include <pj/types.h>
29 #include <pj/compat/setjmp.h>
30 #include <pj/log.h>
31 
32 
34 
35 
242 PJ_DECL(pj_status_t) pj_exception_id_alloc(const char *name,
243  pj_exception_id_t *id);
244 
253 
261 PJ_DECL(const char*) pj_exception_id_name(pj_exception_id_t id);
262 
263 
266 #if defined(PJ_EXCEPTION_USE_WIN32_SEH) && PJ_EXCEPTION_USE_WIN32_SEH != 0
267 /*****************************************************************************
268  **
269  ** IMPLEMENTATION OF EXCEPTION USING WINDOWS SEH
270  **
271  ****************************************************************************/
272 #define WIN32_LEAN_AND_MEAN
273 #include <windows.h>
274 
275 PJ_IDECL_NO_RETURN(void)
276 pj_throw_exception_(pj_exception_id_t id) PJ_ATTR_NORETURN
277 {
278  RaiseException(id,1,0,NULL);
279 }
280 
281 #define PJ_USE_EXCEPTION
282 #define PJ_TRY __try
283 #define PJ_CATCH(id) __except(GetExceptionCode()==id ? \
284  EXCEPTION_EXECUTE_HANDLER : \
285  EXCEPTION_CONTINUE_SEARCH)
286 #define PJ_CATCH_ANY __except(EXCEPTION_EXECUTE_HANDLER)
287 #define PJ_END
288 #define PJ_THROW(id) pj_throw_exception_(id)
289 #define PJ_GET_EXCEPTION() GetExceptionCode()
290 
291 
292 #elif defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0
293 /*****************************************************************************
294  **
295  ** IMPLEMENTATION OF EXCEPTION USING SYMBIAN LEAVE/TRAP FRAMEWORK
296  **
297  ****************************************************************************/
298 
299 /* To include this file, the source file must be compiled as
300  * C++ code!
301  */
302 #ifdef __cplusplus
303 
304 class TPjException
305 {
306 public:
307  int code_;
308 };
309 
310 #define PJ_USE_EXCEPTION
311 #define PJ_TRY try
312 //#define PJ_CATCH(id)
313 #define PJ_CATCH_ANY catch (const TPjException & pj_excp_)
314 #define PJ_END
315 #define PJ_THROW(x_id) do { TPjException e; e.code_=x_id; throw e;} \
316  while (0)
317 #define PJ_GET_EXCEPTION() pj_excp_.code_
318 
319 #else
320 
321 #define PJ_USE_EXCEPTION
322 #define PJ_TRY
323 #define PJ_CATCH_ANY if (0)
324 #define PJ_END
325 #define PJ_THROW(x_id) do { PJ_LOG(1,("PJ_THROW"," error code = %d",x_id)); } while (0)
326 #define PJ_GET_EXCEPTION() 0
327 
328 #endif /* __cplusplus */
329 
330 #else
331 /*****************************************************************************
332  **
333  ** IMPLEMENTATION OF EXCEPTION USING GENERIC SETJMP/LONGJMP
334  **
335  ****************************************************************************/
336 
342 {
343  pj_jmp_buf state;
345 };
346 
351 PJ_DECL_NO_RETURN(void)
352 pj_throw_exception_(pj_exception_id_t id) PJ_ATTR_NORETURN;
353 
357 PJ_DECL(void) pj_push_exception_handler_(struct pj_exception_state_t *rec);
358 
362 PJ_DECL(void) pj_pop_exception_handler_(struct pj_exception_state_t *rec);
363 
368 #define PJ_USE_EXCEPTION struct pj_exception_state_t pj_x_except__; int pj_x_code__
369 
374 #define PJ_TRY if (1) { \
375  pj_push_exception_handler_(&pj_x_except__); \
376  pj_x_code__ = pj_setjmp(pj_x_except__.state); \
377  if (pj_x_code__ == 0)
378 
383 #define PJ_CATCH(id) else if (pj_x_code__ == (id))
384 
389 #define PJ_CATCH_ANY else
390 
395 #define PJ_END pj_pop_exception_handler_(&pj_x_except__); \
396  } else {}
397 
403 #define PJ_THROW(exception_id) pj_throw_exception_(exception_id)
404 
410 #define PJ_GET_EXCEPTION() (pj_x_code__)
411 
412 #endif /* PJ_EXCEPTION_USE_WIN32_SEH */
413 
414 
416 
417 
418 
419 #endif /* __PJ_EXCEPTION_H__ */
420 
421 
void pj_throw_exception_(pj_exception_id_t id) PJ_ATTR_NORETURN
void pj_pop_exception_handler_(struct pj_exception_state_t *rec)
const char * pj_exception_id_name(pj_exception_id_t id)
pj_status_t pj_exception_id_free(pj_exception_id_t id)
Declaration of basic types and utility.
void pj_push_exception_handler_(struct pj_exception_state_t *rec)
int pj_exception_id_t
Definition: types.h:276
struct pj_exception_state_t * prev
Definition: except.h:344
int pj_status_t
Definition: types.h:68
#define PJ_DECL_NO_RETURN(type)
Definition: config.h:1064
Definition: except.h:341
#define PJ_END_DECL
Definition: config.h:1067
#define PJ_IDECL_NO_RETURN(type)
Definition: config.h:1065
#define PJ_BEGIN_DECL
Definition: config.h:1066
pj_status_t pj_exception_id_alloc(const char *name, pj_exception_id_t *id)
Logging Utility.
pj_jmp_buf state
Definition: except.h:343

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.