KDE 4.6 PyKDE API Reference

- KDE's Python API

# KCrash Namespace Reference

`from PyKDE4.kdeui.KCrash import *`

## Detailed Description

This namespace contains functions to handle crashes. It allows you to set a crash handler function that will be called when your application crashes and also provides a default crash handler that implements the following functionality:

- Launches the KDE crash display application (DrKonqi) to let
the user report the bug and/or debug it.
- Calls an emergency save function that you can set with
setEmergencySaveFunction() to attempt to save the application's data.
- Autorestarts your application.

Note:
  All the above features are optional and you need to enable them explicitly. By default, the defaultCrashHandler() will not do anything. However, if you are using KApplication, it will by default enable launching DrKonqi on crashes, unless the --nocrashhandler argument was passed on the command line or the environment variable KDE_DEBUG is set to any value.

## Enumerations

CrashFlag | { KeepFDs, SaferDialog, AlwaysDirectly, AutoRestart }

## Functions

KCrash.HandlerType | crashHandler ()
| defaultCrashHandler (int signal)
KCrash.HandlerType | emergencySaveFunction ()
bool | isDrKonqiEnabled ()
| setApplicationName (QString name)
| setApplicationPath (QString path)
| setCrashHandler (KCrash.HandlerType handler=defaultCrashHandler)
| setDrKonqiEnabled (bool enabled)
| setEmergencySaveFunction (KCrash.HandlerType saveFunction=0)
| setFlags (KCrash.CrashFlags flags)

## Enumeration Documentation

CrashFlag

Options to determine how the default crash handler should behave.

Enumerator:

  KeepFDs = 1 |
  SaferDialog = 2 |
  AlwaysDirectly = 4 |
  AutoRestart = 8 |

## Function Documentation

KCrash.HandlerType crashHandler | ( |  | ) |

Returns the installed crash handler.

Returns:
  the crash handler

defaultCrashHandler | ( | int | signal
| ) |  |  |

The default crash handler. Do not call this function directly. Instead, use setCrashHandler() to set it as your application's crash handler.

Parameters:

  | signal | the signal number

Note:
  If you implement your own crash handler, you will have to call this function from your implementation if you want to use the features of this namespace.

KCrash.HandlerType emergencySaveFunction | ( |  | ) |

Returns the currently set emergency save function.

Returns:
  the emergency save function

bool isDrKonqiEnabled | ( |  | ) |

Returns true if DrKonqi is set to be launched from the crash handler or false otherwise.

Since:
  4.5

setApplicationName | ( | QString | name
| ) |  |  |

Sets the application name which should be passed to DrKonqi, our nice crash display application.

Parameters:

  | name | the name of the application, as shown in DrKonqi

setApplicationPath | ( | QString | path
| ) |  |  |

Sets the application path which should be passed to DrKonqi, our nice crash display application.

Parameters:

  | path | the application path

setCrashHandler | ( | KCrash.HandlerType | handler=defaultCrashHandler
| ) |  |  |

Install a function to be called when a crash occurs. A crash occurs when one of the following signals is caught: SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGABRT.

Parameters:

  | handler | this can be one of:

- null, in which case signal catching is disabled
(by setting the signal handler for the crash signals to SIG_DFL)
- a user defined function in the form:
static (if in a class) void myCrashHandler(int);
- if handler is omitted, the default crash handler is installed

Note:
  If you use setDrKonqiEnabled(true), setEmergencySaveFunction(myfunc) or setFlags(AutoRestart), you do not need to call this function explicitly. The default crash handler is automatically installed by those functions if needed. However, if you set a custom crash handler, those functions will not change it.

setDrKonqiEnabled | ( | bool | enabled
| ) |  |  |

Enables or disables launching DrKonqi from the crash handler. By default, launching DrKonqi is disabled. However, KApplication will enable it in its constructor, so you don't need to call this function if you are using KApplication.

Note:
  It is the crash handler's responsibility to launch DrKonqi. Therefore, if no crash handler is set, this method also installs the default crash handler to ensure that DrKonqi will be launched.

Since:
  4.5

setEmergencySaveFunction | ( | KCrash.HandlerType | saveFunction=0
| ) |  |  |

Installs a function which should try to save the application's data.

Note:
  It is the crash handler's responsibility to call this function. Therefore, if no crash handler is set, the default crash handler is installed to ensure the save function will be called.

Parameters:

  | saveFunction | the handler to install

setFlags | ( | KCrash.CrashFlags | flags
| ) |  |  |

Set options to determine how the default crash handler should behave.

Parameters:

  | flags | ORed together CrashFlags