1 /* go-panic.c -- support for the go panic function.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
16 #include "go-string.h"
17 #include "interface.h"
19 /* Print the panic stack. This is used when there is no recover. */
22 __printpanics (struct __go_panic_stack
*p
)
24 if (p
->__next
!= NULL
)
26 __printpanics (p
->__next
);
27 fprintf (stderr
, "\t");
29 fprintf (stderr
, "panic: ");
30 runtime_printany (p
->__arg
);
31 if (p
->__was_recovered
)
32 fprintf (stderr
, " [recovered]");
36 /* This implements __go_panic which is used for the panic
40 __go_panic (struct __go_empty_interface arg
)
43 struct __go_panic_stack
*n
;
47 n
= (struct __go_panic_stack
*) __go_alloc (sizeof (struct __go_panic_stack
));
52 /* Run all the defer functions. */
56 struct __go_defer_stack
*d
;
70 if (n
->__was_recovered
)
72 /* Some defer function called recover. That means that
73 we should stop running this panic. */
78 /* Now unwind the stack by throwing an exception. The
79 compiler has arranged to create exception handlers in
80 each function which uses a defer statement. These
81 exception handlers will check whether the entry on
82 the top of the defer stack is from the current
83 function. If it is, we have unwound the stack far
87 /* __go_unwind_stack should not return. */
91 /* Because we executed that defer function by a panic, and
92 it did not call recover, we know that we are not
93 returning from the calling function--we are panicing
102 /* The panic was not recovered. */
104 runtime_startpanic ();
105 __printpanics (g
->panic
);