grub2: bring back build of aros-side grub2 tools
[AROS.git] / test / cplusplus / exception.cpp
blob59a2692319e9952e749bb55e5c26deb5d7a69dc6
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 * We use printf() here instead of C++ traditional cout because linking in cout
8 * increases executable size up to 3 megabytes (!!!), making it difficult to
9 * disassemble it. Anyway our aim is to test exceptions.
12 #include <stdio.h>
13 #include <stdlib.h>
15 #ifdef __AROS__
17 #include <exec/alerts.h>
18 #include <proto/exec.h>
20 extern void *__eh_frame_start;
23 * Non-working call frame unwinding in AROS causes calling abort().
24 * Here we manually override this function to call Alert(),
25 * which can give us a stack trace.
27 void abort(void)
29 printf("abort() called\n");
31 Alert(AN_Unknown);
33 /* Calling exit here makes this a noreturn function
34 * avoiding a compiler warning. */
35 exit(20);
38 #endif
40 /* Just to make things a little bit more complex. */
41 int sub()
43 printf("sub() entered\n");
45 throw 20;
48 int main ()
50 #ifdef __AROS__
51 printf("Exception frames start at %p\n", &__eh_frame_start);
52 #endif
54 try
56 sub();
58 catch (int e)
60 printf("An exception occurred. Exception Nr. %d\n", e);
63 printf("Exiting\n");
64 return 0;