]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/error.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: error.h,v 1.4 1998/09/12 02:46:27 jgg Exp $
4 /* ######################################################################
6 Global Erorr Class - Global error mechanism
8 This class has a single global instance. When a function needs to
9 generate an error condition, such as a read error, it calls a member
10 in this class to add the error to a stack of errors.
12 By using a stack the problem with a scheme like errno is removed and
13 it allows a very detailed account of what went wrong to be transmitted
14 to the UI for display. (Errno has problems because each function sets
15 errno to 0 if it didn't have an error thus eraseing erno in the process
18 Several predefined error generators are provided to handle common
19 things like errno. The general idea is that all methods return a bool.
20 If the bool is true then things are OK, if it is false then things
21 should start being undone and the stack should unwind under program
24 A Warning should not force the return of false. Things did not fail, but
25 they might have had unexpected problems. Errors are stored in a FIFO
26 so Pop will return the first item..
28 I have some thoughts about extending this into a more general UI<->
29 Engine interface, ie allowing the Engine to say 'The disk is full' in
30 a dialog that says 'Panic' and 'Retry'.. The error generator functions
31 like errno, Warning and Error return false always so this is normal:
33 return _error->Errno(..);
35 This source is placed in the Public Domain, do with it what you will
36 It was originally written by Jason Gunthorpe.
38 ##################################################################### */
40 // Header section: pkglib
41 #ifndef PKGLIB_ERROR_H
42 #define PKGLIB_ERROR_H
45 #pragma interface "apt-pkg/error.h"
65 // Call to generate an error from a library call.
66 bool Errno(const char *Function
,const char *Description
,...);
68 /* A warning should be considered less severe than an error, and may be
69 ignored by the client. */
70 bool Error(const char *Description
,...);
71 bool Warning(const char *Description
,...);
74 inline bool PendingError() {return PendingFlag
;};
75 inline bool empty() {return List
== 0;};
76 bool PopMessage(string
&Text
);
79 // Usefull routine to dump to cerr
85 // The 'extra-ansi' syntax is used to help with collisions.
86 GlobalError
*_GetErrorObj();
87 #define _error _GetErrorObj()