BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJLIB Reference

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

 


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