Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c15796431234c33bc37f7d46e288fc41160d4968
[simgrid.git] / src / xbt / ex.c
1 /*
2 **  OSSP ex - Exception Handling
3 **  Copyright (c) 2002-2004 Ralf S. Engelschall <rse@engelschall.com>
4 **  Copyright (c) 2002-2004 The OSSP Project <http://www.ossp.org/>
5 **  Copyright (c) 2002-2004 Cable & Wireless <http://www.cw.com/>
6 **
7 **  This file is part of OSSP ex, an exception handling library
8 **  which can be found at http://www.ossp.org/pkg/lib/ex/.
9 **
10 **  Permission to use, copy, modify, and distribute this software for
11 **  any purpose with or without fee is hereby granted, provided that
12 **  the above copyright notice and this permission notice appear in all
13 **  copies.
14 **
15 **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
16 **  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 **  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
19 **  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 **  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 **  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 **  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 **  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 **  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 **  SUCH DAMAGE.
27 **
28 **  ex.c: exception handling (compiler part)
29 */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33
34 #include "xbt/ex.h"
35
36 /* default __ex_ctx callback function */
37 ex_ctx_t *__ex_ctx_default(void)
38 {
39     static ex_ctx_t ctx = EX_CTX_INITIALIZER;
40
41     return &ctx;
42 }
43
44 /* default __ex_terminate callback function */
45 void __ex_terminate_default(ex_t *e)
46 {
47     fprintf(stderr,
48             "**EX: UNCAUGHT EXCEPTION: "
49             "class=0x%lx object=0x%lx value=0x%lx [%s:%d@%s]\n",
50             (long)((e)->ex_class), (long)((e)->ex_object), (long)((e)->ex_value),
51             (e)->ex_file, (e)->ex_line, (e)->ex_func);
52     abort();
53 }
54
55 /* the externally visible API */
56 ex_ctx_cb_t  __ex_ctx       = &__ex_ctx_default;
57 ex_term_cb_t __ex_terminate = &__ex_terminate_default;
58