PedException

Exception handling. More...

Files

file  exception.h

Data Structures

struct  _PedException
 Structure with information about exception. More...

Defines

#define _(String)   (String)
#define N_(String)   String
#define PED_EXCEPTION_IGNORE_CANCEL
#define PED_EXCEPTION_OK_CANCEL   (PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL)
#define PED_EXCEPTION_OPTION_FIRST   PED_EXCEPTION_FIX
#define PED_EXCEPTION_OPTION_LAST   PED_EXCEPTION_CANCEL
#define PED_EXCEPTION_RETRY_CANCEL   (PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL)
#define PED_EXCEPTION_RETRY_IGNORE_CANCEL
#define PED_EXCEPTION_YES_NO   (PED_EXCEPTION_YES + PED_EXCEPTION_NO)
#define PED_EXCEPTION_YES_NO_CANCEL

Typedefs

typedef _PedException PedException
typedef PedExceptionOption( PedExceptionHandler )(PedException *ex)
typedef enum _PedExceptionOption PedExceptionOption
typedef enum _PedExceptionType PedExceptionType

Enumerations

enum  _PedExceptionOption {
  PED_EXCEPTION_UNHANDLED = 0, PED_EXCEPTION_FIX = 1, PED_EXCEPTION_YES = 2, PED_EXCEPTION_NO = 4,
  PED_EXCEPTION_OK = 8, PED_EXCEPTION_RETRY = 16, PED_EXCEPTION_IGNORE = 32, PED_EXCEPTION_CANCEL = 64
}
 Option for resolving the exception.
enum  _PedExceptionType {
  PED_EXCEPTION_INFORMATION = 1, PED_EXCEPTION_WARNING = 2, PED_EXCEPTION_ERROR = 3, PED_EXCEPTION_FATAL = 4,
  PED_EXCEPTION_BUG = 5, PED_EXCEPTION_NO_FEATURE = 6
}
 Exception type.

Functions

void ped_exception_catch ()
 Assert that the current exception has been resolved.
PedExceptionOption ped_exception_default_handler (PedException *ex)
void ped_exception_fetch_all ()
 Indicates that exceptions should not go to the exception handler, but passed up to the calling function(s).
PedExceptionHandler * ped_exception_get_handler (void)
 Get the current exception handler.
char * ped_exception_get_option_string (PedExceptionOption ex_opt)
 Return a string describing an exception option.
char * ped_exception_get_type_string (PedExceptionType ex_type)
 Return a string describing an exception type.
void ped_exception_leave_all ()
 Indicates that the calling function does not want to accept any responsibility for exceptions any more.
PedExceptionOption ped_exception_rethrow ()
 Rethrow an unhandled exception.
void ped_exception_set_handler (PedExceptionHandler *handler)
 Set the exception handler.
PedExceptionOption ped_exception_throw (PedExceptionType ex_type, PedExceptionOption ex_opts, const char *message,...)
 Throw an exception.

Variables

int ped_exception
int ped_exception = 0

Detailed Description

Exception handling.

There are a few types of exceptions: PED_EXCEPTION_INFORMATION, PED_EXCEPTION_WARNING, PED_EXCEPTION_ERROR, PED_EXCEPTION_FATAL, PED_EXCEPTION_BUG.

They are "thrown" when one of the above events occur while executing a libparted function. For example, if ped_device_open() fails because the device doesn't exist, an exception will be thrown. Exceptions contain text describing what the event was. It will give at least one option for resolving the exception: PED_EXCEPTION_FIX, PED_EXCEPTION_YES, PED_EXCEPTION_NO, PED_EXCEPTION_OK, PED_EXCEPTION_RETRY, PED_EXCEPTION_IGNORE, PED_EXCEPTION_CANCEL. After an exception is thrown, there are two things that can happen:

  1. an exception handler is called, which selects how the exception should be resolved (usually by asking the user). Also note: an exception handler may choose to return PED_EXCEPTION_UNHANDLED. In this case, a default action will be taken by libparted (respectively the code that threw the exception). In general, a default action will be "safe".
  2. the exception is not handled, because the caller of the function wants to handle everything itself. In this case, PED_EXCEPTION_UNHANDLED is returned.

Define Documentation

#define PED_EXCEPTION_IGNORE_CANCEL

Value:

(PED_EXCEPTION_IGNORE \
                                     + PED_EXCEPTION_CANCEL)

#define PED_EXCEPTION_RETRY_IGNORE_CANCEL

Value:

(PED_EXCEPTION_RETRY \
                                           + PED_EXCEPTION_IGNORE_CANCEL)

#define PED_EXCEPTION_YES_NO_CANCEL

Value:

(PED_EXCEPTION_YES_NO \
                                     + PED_EXCEPTION_CANCEL)


Function Documentation

void ped_exception_fetch_all (  ) 

Indicates that exceptions should not go to the exception handler, but passed up to the calling function(s).

All calls to ped_exception_throw() will return PED_EXCEPTION_UNHANDLED.

void ped_exception_leave_all (  ) 

Indicates that the calling function does not want to accept any responsibility for exceptions any more.

Note:
a caller of that function may still want responsibility, so ped_exception_throw() may not invoke the exception handler.
Warning:
every call to this function must have a preceding ped_exception_fetch_all().

PedExceptionOption ped_exception_rethrow (  ) 

Rethrow an unhandled exception.

This means repeating the last ped_exception_throw() statement.

void ped_exception_set_handler ( PedExceptionHandler *  handler  ) 

Set the exception handler.

The exception handler should return ONE of the options set in ex->options, indicating the way the event should be resolved.

PedExceptionOption ped_exception_throw ( PedExceptionType  ex_type,
PedExceptionOption  ex_opts,
const char *  message,
  ... 
)

Throw an exception.

You can also use this in a program using libparted. "message" is a printf-like format string, so you can do

 ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_RETRY_CANCEL,
      "Can't open %s", file_name);

Returns the option selected to resolve the exception. If the exception was unhandled, PED_EXCEPTION_UNHANDLED is returned.


Generated on Fri May 4 05:15:31 2007 for libparted by  doxygen 1.5.2