File: StreamError.h

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (83 lines) | stat: -rw-r--r-- 1,770 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include "Core/Exception.h"

namespace storm {
	STORM_PKG(core.io);

	/**
	 * Exception thrown for IO errors.
	 *
	 * Note that this is only used for major errors. End-of-stream and failure to write are not
	 * treated as major errors, and are handled through return codes instead. Exceptions indicate
	 * major problems with the IO system as a whole.
	 */
	class EXCEPTION_EXPORT IoError : public Exception {
		STORM_EXCEPTION;
	public:
		IoError(const wchar *msg) {
			w = new (this) Str(msg);
			saveTrace();
		}
		STORM_CTOR IoError(Str *msg) {
			w = msg;
			saveTrace();
		}

		virtual void STORM_FN message(StrBuf *to) const {
			*to << w;
		}
	private:
		Str *w;
	};


	namespace sys {
		/**
		 * System error codes for IO streams. Available from the `error` member of input- and output
		 * streams.
		 */
		enum ErrorCode {
			// No error. Use `any` or `empty` to check conveniently.
			none = 0,

			// Unknown error.
			unknown,

			// Low-level IO error.
			ioError,

			// The file is too big for the underlying file system to handle.
			tooLargeFile,

			// Out of space on the underlying device.
			outOfSpace,

			// The file (or a part of the file) was locked.
			fileLocked,

			// Remote end of pipe disconnected.
			disconnected,

			// Stream closed.
			closed,
		};

		// See if there was any error?
		inline Bool STORM_FN any(ErrorCode c) {
			return c != none;
		}
		inline Bool STORM_FN empty(ErrorCode c) {
			return c == none;
		}

		// Get a description of the error.
		Str *STORM_FN description(EnginePtr e, ErrorCode c);

		// Throw an error code as an exception, unless it is `none`.
		void STORM_FN throwError(EnginePtr e, ErrorCode c);
	}

	// Convert from system error code.
	sys::ErrorCode fromSystemError(int error);

}