2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * A class for managing error numbers and strings.
13 * A class for managing error numbers and strings.
15 * It can have either a system error value, like those defined
16 * in errno.h, or an arbitrary error string. In either case, it
17 * can return a string representation of the error message.
19 * This object is most useful for using as a base class of your own class,
20 * for historical/backwards compatibility reasons. Consider using a WvError
21 * instead, and making it a member of your class instead of a parent.
32 virtual ~WvErrorBase();
35 * By default, returns true if geterr() == 0.
36 * Might be overridden so that isok() == false even though no
37 * error code has been specified.
39 virtual bool isok() const
40 { return errnum
== 0; }
43 * If isok() is false, return the system error number corresponding to
44 * the error, -1 for a special error string (which you can obtain with
45 * errstr()) or 0 on end of file. If isok() is true, returns an
48 virtual int geterr() const
50 virtual WvString
errstr() const;
53 * A replacement for the operating system ::strerror() function that
54 * can map more kinds of error strings (especially in win32).
56 static WvString
strerror(int errnum
);
59 * Set the errnum variable -- we have an error. If called more than
60 * once, seterr() doesn't change the error code away from the previous
61 * one. That way, we remember the _original_ cause of our problems.
63 * Subclasses may want to override seterr(int) to shut themselves down
64 * (eg. WvStream::close()) when an error condition is set.
66 * Note that seterr(WvString) will call seterr(-1).
68 virtual void seterr(int _errnum
);
69 void seterr(WvStringParm specialerr
);
70 void seterr(WVSTRING_FORMAT_DECL
)
71 { seterr(WvString(WVSTRING_FORMAT_CALL
)); }
72 void seterr_both(int _errnum
, WvStringParm specialerr
);
73 void seterr_both(int _errnum
, WVSTRING_FORMAT_DECL
)
74 { seterr_both(_errnum
, WvString(WVSTRING_FORMAT_CALL
)); }
75 void seterr(const WvErrorBase
&err
);
77 /** Reset our error state - there's no error condition anymore. */
79 { errnum
= 0; errstring
= WvString::null
; }
84 * A variant of WvErrorBase suitable for embedding as a member of your own
85 * object, preferably called 'err'. It adds some extra convenience functions
86 * to remove function name redundancy, so you can say "obj.err.get()" instead
87 * of "obj.err.geterr()", for example.
89 class WvError
: public WvErrorBase
99 void set(WvStringParm specialerr
)
100 { seterr(specialerr
); }
101 void set(WVSTRING_FORMAT_DECL
)
102 { seterr(WvString(WVSTRING_FORMAT_CALL
)); }
103 void set_both(int _errnum
, WvStringParm specialerr
)
104 { seterr_both(_errnum
, specialerr
); }
105 void set(const WvErrorBase
&err
)
113 #endif // __WVERROR_H