Skip to content

Commit 2fbfc15

Browse files
committed
Use gcc's __EXCEPTIONS until I find a more portable way
Also use cerr instead of clog
1 parent d6bb331 commit 2fbfc15

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

README.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ loading a shader into OpenGL.
2525
glShaderSource(shader, map.length(), *map, NULL);
2626
// the file is automatically unmapped if map goes out of scope
2727

28-
If you don't want to use exceptions define `NO_EXCEPTIONS`. mapped_file will
29-
then call exit(1) if an error occurs.
28+
If you don't want to use exceptions compile with -fno-exceptions.
29+
mapped_file will then call exit(1) if an error occurs.
30+
MSVC Users: You have to define __EXCEPTIONS if you want exceptions.
3031

3132
Supported Operating Systems
3233
---------------------------

mappedfile.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ void unmap_file(char *data, size_t length);
4747
}
4848

4949
#include <cstddef>
50-
#ifndef NO_EXCEPTIONS
50+
#ifdef __EXCEPTIONS
5151
#include <stdexcept>
5252
#include <sstream>
53-
#else /* NO_EXCEPTIONS */
53+
#else /* __EXCEPTIONS */
5454
#include <cstdlib>
5555
#include <iostream>
56-
#endif /* NO_EXCEPTIONS */
56+
#endif /* __EXCEPTIONS */
5757

5858
/*!
5959
* mapped_file allows you to create a simple read-only file mapping in an
@@ -76,14 +76,14 @@ class mapped_file
7676
mapped_file(const char *path) : size_(), data_() {
7777
data_ = map_file(path, &size_);
7878
if (!data_) {
79-
#ifndef NO_EXCEPTIONS
79+
#ifdef __EXCEPTIONS
8080
std::ostringstream o;
8181
o << "Couldn't open File \"" << path << "\"";
8282
throw io_exception(o.str());
83-
#else /* NO_EXCEPTIONS */
84-
std::clog << "Couldn't open File \"" << path << "\"" << std::endl;
83+
#else /* __EXCEPTIONS */
84+
std::cerr << "Couldn't open File \"" << path << "\"" << std::endl;
8585
std::exit(EXIT_FAILURE);
86-
#endif /* NO_EXCEPTIONS */
86+
#endif /* __EXCEPTIONS */
8787
}
8888
}
8989
/*!
@@ -105,13 +105,13 @@ class mapped_file
105105
*/
106106
const char* operator*() const { return data_; }
107107

108-
#ifndef NO_EXCEPTIONS
108+
#ifdef __EXCEPTIONS
109109
struct io_exception : public std::runtime_error
110110
{
111111
io_exception(const std::string& message)
112112
: std::runtime_error(message) { }
113113
};
114-
#endif /* NO_EXCEPTIONS */
114+
#endif /* __EXCEPTIONS */
115115
};
116116
#endif /* __cplusplus */
117117

0 commit comments

Comments
 (0)