libparted 3.6
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
PedException

Exception handling. More...

Files

file  exception.h
 
file  exception.h
 

Data Structures

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

Macros

#define _(String)   (String)
 
#define N_(String)   String
 
#define PED_EXCEPTION_OPTION_FIRST   PED_EXCEPTION_FIX
 
#define PED_EXCEPTION_OPTION_FIRST   PED_EXCEPTION_FIX
 
#define PED_EXCEPTION_OPTION_LAST   PED_EXCEPTION_CANCEL /* last individual option */
 
#define PED_EXCEPTION_OPTION_LAST   PED_EXCEPTION_CANCEL /* last individual option */
 

Typedefs

typedef struct _PedException PedException
 
typedef struct _PedException PedException
 
typedef PedExceptionOption() PedExceptionHandler(PedException *ex)
 
typedef PedExceptionOption() PedExceptionHandler(PedException *ex)
 
typedef enum _PedExceptionOption PedExceptionOption
 
typedef enum _PedExceptionOption PedExceptionOption
 
typedef enum _PedExceptionType PedExceptionType
 
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 ,
  PED_EXCEPTION_OK_CANCEL = PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL , PED_EXCEPTION_YES_NO = PED_EXCEPTION_YES + PED_EXCEPTION_NO , PED_EXCEPTION_YES_NO_CANCEL , PED_EXCEPTION_IGNORE_CANCEL ,
  PED_EXCEPTION_RETRY_CANCEL = PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL , PED_EXCEPTION_RETRY_IGNORE_CANCEL , 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 , PED_EXCEPTION_OK_CANCEL = PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL , PED_EXCEPTION_YES_NO = PED_EXCEPTION_YES + PED_EXCEPTION_NO ,
  PED_EXCEPTION_YES_NO_CANCEL , PED_EXCEPTION_IGNORE_CANCEL , PED_EXCEPTION_RETRY_CANCEL = PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL , PED_EXCEPTION_RETRY_IGNORE_CANCEL
}
 Option for resolving the exception. More...
 
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 ,
  PED_EXCEPTION_OK_CANCEL = PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL , PED_EXCEPTION_YES_NO = PED_EXCEPTION_YES + PED_EXCEPTION_NO , PED_EXCEPTION_YES_NO_CANCEL , PED_EXCEPTION_IGNORE_CANCEL ,
  PED_EXCEPTION_RETRY_CANCEL = PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL , PED_EXCEPTION_RETRY_IGNORE_CANCEL , 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 , PED_EXCEPTION_OK_CANCEL = PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL , PED_EXCEPTION_YES_NO = PED_EXCEPTION_YES + PED_EXCEPTION_NO ,
  PED_EXCEPTION_YES_NO_CANCEL , PED_EXCEPTION_IGNORE_CANCEL , PED_EXCEPTION_RETRY_CANCEL = PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL , PED_EXCEPTION_RETRY_IGNORE_CANCEL
}
 Option for resolving the exception. More...
 
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 , 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. More...
 
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 , 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. More...
 

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).
 
PedExceptionHandlerped_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
 
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.

Macro Definition Documentation

◆ _

#define _ (   String)    (String)

◆ N_

#define N_ (   String)    String

◆ PED_EXCEPTION_OPTION_FIRST [1/2]

#define PED_EXCEPTION_OPTION_FIRST   PED_EXCEPTION_FIX

◆ PED_EXCEPTION_OPTION_FIRST [2/2]

#define PED_EXCEPTION_OPTION_FIRST   PED_EXCEPTION_FIX

◆ PED_EXCEPTION_OPTION_LAST [1/2]

#define PED_EXCEPTION_OPTION_LAST   PED_EXCEPTION_CANCEL /* last individual option */

◆ PED_EXCEPTION_OPTION_LAST [2/2]

#define PED_EXCEPTION_OPTION_LAST   PED_EXCEPTION_CANCEL /* last individual option */

Typedef Documentation

◆ PedException [1/2]

typedef struct _PedException PedException

◆ PedException [2/2]

typedef struct _PedException PedException

◆ PedExceptionHandler [1/2]

typedef PedExceptionOption() PedExceptionHandler(PedException *ex)

◆ PedExceptionHandler [2/2]

typedef PedExceptionOption() PedExceptionHandler(PedException *ex)

◆ PedExceptionOption [1/2]

◆ PedExceptionOption [2/2]

◆ PedExceptionType [1/2]

◆ PedExceptionType [2/2]

Enumeration Type Documentation

◆ _PedExceptionOption [1/2]

Option for resolving the exception.

Enumerator
PED_EXCEPTION_UNHANDLED 
PED_EXCEPTION_FIX 
PED_EXCEPTION_YES 
PED_EXCEPTION_NO 
PED_EXCEPTION_OK 
PED_EXCEPTION_RETRY 
PED_EXCEPTION_IGNORE 
PED_EXCEPTION_CANCEL 
PED_EXCEPTION_OK_CANCEL 
PED_EXCEPTION_YES_NO 
PED_EXCEPTION_YES_NO_CANCEL 
PED_EXCEPTION_IGNORE_CANCEL 
PED_EXCEPTION_RETRY_CANCEL 
PED_EXCEPTION_RETRY_IGNORE_CANCEL 
PED_EXCEPTION_UNHANDLED 
PED_EXCEPTION_FIX 
PED_EXCEPTION_YES 
PED_EXCEPTION_NO 
PED_EXCEPTION_OK 
PED_EXCEPTION_RETRY 
PED_EXCEPTION_IGNORE 
PED_EXCEPTION_CANCEL 
PED_EXCEPTION_OK_CANCEL 
PED_EXCEPTION_YES_NO 
PED_EXCEPTION_YES_NO_CANCEL 
PED_EXCEPTION_IGNORE_CANCEL 
PED_EXCEPTION_RETRY_CANCEL 
PED_EXCEPTION_RETRY_IGNORE_CANCEL 

◆ _PedExceptionOption [2/2]

Option for resolving the exception.

Enumerator
PED_EXCEPTION_UNHANDLED 
PED_EXCEPTION_FIX 
PED_EXCEPTION_YES 
PED_EXCEPTION_NO 
PED_EXCEPTION_OK 
PED_EXCEPTION_RETRY 
PED_EXCEPTION_IGNORE 
PED_EXCEPTION_CANCEL 
PED_EXCEPTION_OK_CANCEL 
PED_EXCEPTION_YES_NO 
PED_EXCEPTION_YES_NO_CANCEL 
PED_EXCEPTION_IGNORE_CANCEL 
PED_EXCEPTION_RETRY_CANCEL 
PED_EXCEPTION_RETRY_IGNORE_CANCEL 
PED_EXCEPTION_UNHANDLED 
PED_EXCEPTION_FIX 
PED_EXCEPTION_YES 
PED_EXCEPTION_NO 
PED_EXCEPTION_OK 
PED_EXCEPTION_RETRY 
PED_EXCEPTION_IGNORE 
PED_EXCEPTION_CANCEL 
PED_EXCEPTION_OK_CANCEL 
PED_EXCEPTION_YES_NO 
PED_EXCEPTION_YES_NO_CANCEL 
PED_EXCEPTION_IGNORE_CANCEL 
PED_EXCEPTION_RETRY_CANCEL 
PED_EXCEPTION_RETRY_IGNORE_CANCEL 

◆ _PedExceptionType [1/2]

Exception type.

Enumerator
PED_EXCEPTION_INFORMATION 
PED_EXCEPTION_WARNING 
PED_EXCEPTION_ERROR 
PED_EXCEPTION_FATAL 
PED_EXCEPTION_BUG 
PED_EXCEPTION_NO_FEATURE 
PED_EXCEPTION_INFORMATION 
PED_EXCEPTION_WARNING 
PED_EXCEPTION_ERROR 
PED_EXCEPTION_FATAL 
PED_EXCEPTION_BUG 
PED_EXCEPTION_NO_FEATURE 

◆ _PedExceptionType [2/2]

Exception type.

Enumerator
PED_EXCEPTION_INFORMATION 
PED_EXCEPTION_WARNING 
PED_EXCEPTION_ERROR 
PED_EXCEPTION_FATAL 
PED_EXCEPTION_BUG 
PED_EXCEPTION_NO_FEATURE 
PED_EXCEPTION_INFORMATION 
PED_EXCEPTION_WARNING 
PED_EXCEPTION_ERROR 
PED_EXCEPTION_FATAL 
PED_EXCEPTION_BUG 
PED_EXCEPTION_NO_FEATURE 

Function Documentation

◆ ped_exception_catch()

void ped_exception_catch ( )

Assert that the current exception has been resolved.

◆ ped_exception_default_handler()

PedExceptionOption ped_exception_default_handler ( PedException ex)

◆ ped_exception_fetch_all()

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.

◆ ped_exception_get_handler()

PedExceptionHandler * ped_exception_get_handler ( void  )

Get the current exception handler.

◆ ped_exception_get_option_string()

char * ped_exception_get_option_string ( PedExceptionOption  ex_opt)

Return a string describing an exception option.

◆ ped_exception_get_type_string()

char * ped_exception_get_type_string ( PedExceptionType  ex_type)

Return a string describing an exception type.

◆ ped_exception_leave_all()

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().

◆ ped_exception_rethrow()

PedExceptionOption ped_exception_rethrow ( )

Rethrow an unhandled exception.

This means repeating the last ped_exception_throw() statement.

◆ ped_exception_set_handler()

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.

◆ ped_exception_throw()

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

"Can't open %s", file_name);
PedExceptionOption ped_exception_throw(PedExceptionType ex_type, PedExceptionOption ex_opt, const char *message,...)
Throw an exception.
Definition: exception.c:230
@ PED_EXCEPTION_ERROR
Definition: exception.h:38
@ PED_EXCEPTION_RETRY_CANCEL
Definition: exception.h:66

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

Variable Documentation

◆ ped_exception [1/3]

int ped_exception
extern

◆ ped_exception [2/3]

int ped_exception
extern

◆ ped_exception [3/3]

int ped_exception = 0