14
14
15
15
#include < string>
16
16
#include < vector>
17
+ #include < stdexcept>
17
18
18
19
#ifdef __has_include
19
20
#if __has_include(<unistd.h>)
@@ -74,7 +75,7 @@ struct llama_file {
74
75
llama_file (const char * fname, const char * mode) {
75
76
fp = std::fopen (fname, mode);
76
77
if (fp == NULL ) {
77
- throw format (" failed to open %s: %s" , fname, std:: strerror (errno));
78
+ throw std::runtime_error ( format (" failed to open %s: %s" , fname, strerror (errno) ));
78
79
}
79
80
seek (0 , SEEK_END);
80
81
size = tell ();
@@ -107,10 +108,10 @@ struct llama_file {
107
108
errno = 0 ;
108
109
std::size_t ret = std::fread (ptr, size, 1 , fp);
109
110
if (ferror (fp)) {
110
- throw format (" read error: %s" , strerror (errno));
111
+ throw std::runtime_error ( format (" read error: %s" , strerror (errno) ));
111
112
}
112
113
if (ret != 1 ) {
113
- throw std::string (" unexpectedly reached end of file" );
114
+ throw std::runtime_error ( std:: string (" unexpectedly reached end of file" ) );
114
115
}
115
116
}
116
117
@@ -133,7 +134,7 @@ struct llama_file {
133
134
errno = 0 ;
134
135
size_t ret = std::fwrite (ptr, size, 1 , fp);
135
136
if (ret != 1 ) {
136
- throw format (" write error: %s" , strerror (errno));
137
+ throw std::runtime_error ( format (" write error: %s" , strerror (errno) ));
137
138
}
138
139
}
139
140
@@ -180,7 +181,7 @@ struct llama_mmap {
180
181
#endif
181
182
addr = mmap (NULL , file->size , PROT_READ, flags, fd, 0 );
182
183
if (addr == MAP_FAILED) {
183
- throw format (" mmap failed: %s" , strerror (errno));
184
+ throw std::runtime_error ( format (" mmap failed: %s" , strerror (errno) ));
184
185
}
185
186
186
187
if (prefetch) {
@@ -207,15 +208,15 @@ struct llama_mmap {
207
208
DWORD error = GetLastError ();
208
209
209
210
if (hMapping == NULL ) {
210
- throw format (" CreateFileMappingA failed: %s" , llama_format_win_err (error).c_str ());
211
+ throw std::runtime_error ( format (" CreateFileMappingA failed: %s" , llama_format_win_err (error).c_str () ));
211
212
}
212
213
213
214
addr = MapViewOfFile (hMapping, FILE_MAP_READ, 0 , 0 , 0 );
214
215
error = GetLastError ();
215
216
CloseHandle (hMapping);
216
217
217
218
if (addr == NULL ) {
218
- throw format (" MapViewOfFile failed: %s" , llama_format_win_err (error).c_str ());
219
+ throw std::runtime_error ( format (" MapViewOfFile failed: %s" , llama_format_win_err (error).c_str () ));
219
220
}
220
221
221
222
#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
@@ -245,7 +246,7 @@ struct llama_mmap {
245
246
246
247
llama_mmap (struct llama_file *, bool prefetch = true ) {
247
248
(void )prefetch;
248
- throw std::string (" mmap not supported" );
249
+ throw std::runtime_error ( std:: string (" mmap not supported" ) );
249
250
}
250
251
#endif
251
252
};
0 commit comments