---
name: "panic"
section: "3tcl"
platform: "linux"
package: "tcl8.4-doc"
version: "8.4.19-5"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/Tcl_Panic/3tcl"
---

# panic(3tcl)

report fatal error and abort

Part of [Tcl\_Panic(3tcl)](/Tcl_Panic/3tcl.md).

```

```

## NAME

Tcl\_Panic, Tcl\_PanicVA, Tcl\_SetPanicProc, panic, panicVA - report fatal error and abort

## SYNOPSIS

```
#include <tcl.h>

void
Tcl_Panic(format, arg, arg, ...)

void
Tcl_PanicVA(format, argList)

void
Tcl_SetPanicProc(panicProc)

void
panic(format, arg, arg, ...)

void
panicVA(format, argList)

```

## ARGUMENTS

- CONST char\* *format* (in)

  A printf-style format string.

- *arg* (in)

  Arguments matching the format string.

- va\_list *argList* (in)

  An argument list of arguments matching the format string. Must have been initialized using **TCL\_VARARGS\_START**, and cleared using **va\_end**.

- Tcl\_PanicProc *\*panicProc* (in)

  Procedure to report fatal error message and abort.

  ```

  ```

## DESCRIPTION

When the Tcl library detects that its internal data structures are in an inconsistent state, or that its C procedures have been called in a manner inconsistent with their documentation, it calls **Tcl\_Panic** to display a message describing the error and abort the process.  The *format* argument is a format string describing how to format the remaining arguments *arg* into an error message, according to the same formatting rules used by the **printf** family of functions.  The same formatting rules are also used by the builtin Tcl command **format**.

In a freshly loaded Tcl library, **Tcl\_Panic** prints the formatted error message to the standard error file of the process, and then calls **abort** to terminate the process.  **Tcl\_Panic** does not return.

**Tcl\_SetPanicProc** may be used to modify the behavior of **Tcl\_Panic**.  The *panicProc* argument should match the type **Tcl\_PanicProc**:

```
typedef void Tcl_PanicProc(
	CONST char *format,
	arg, arg,...);
```

After **Tcl\_SetPanicProc** returns, any future calls to **Tcl\_Panic** will call *panicProc*, passing along the *format* and *arg* arguments.  To maintain consistency with the callers of **Tcl\_Panic**, *panicProc* must not return; it must call **abort**.  *panicProc* should avoid making calls into the Tcl library, or into other libraries that may call the Tcl library, since the original call to **Tcl\_Panic** indicates the Tcl library is not in a state of reliable operation.

The typical use of **Tcl\_SetPanicProc** arranges for the error message to be displayed or reported in a manner more suitable for the application or the platform.  As an example, the Windows implementation of **wish** calls **Tcl\_SetPanicProc** to force all panic messages to be displayed in a system dialog box, rather than to be printed to the standard error file (usually not visible under Windows).

Although the primary callers of **Tcl\_Panic** are the procedures of the Tcl library, **Tcl\_Panic** is a public function and may be called by any extension or application that wishes to abort the process and have a panic message displayed the same way that panic messages from Tcl will be displayed.

**Tcl\_PanicVA** is the same as **Tcl\_Panic** except that instead of taking a variable number of arguments it takes an argument list.  The procedures **panic** and **panicVA** are synonyms (implemented as macros) for **Tcl\_Panic** and **Tcl\_PanicVA**, respectively.  They exist to support old code; new code should use direct calls to **Tcl\_Panic** or **Tcl\_PanicVA**.

## SEE ALSO

[abort(3)](/abort/3.md), [printf(3)](/printf/3.md), [exec(3tcl)](/exec/3tcl.md), [format(3tcl)](/format/3tcl.md)

## KEYWORDS

abort, fatal, error
