Skip to content

Commit 0ab8fb1

Browse files
authored
Merge pull request #105 from n-riesco/dont-throw-cpp-exceptions
binding.cc: Don't throw cpp exceptions
2 parents b310ab5 + 618bd73 commit 0ab8fb1

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

binding.cc

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ namespace zmq {
240240

241241
Context::Context(int io_threads) : Nan::ObjectWrap() {
242242
context_ = zmq_init(io_threads);
243-
if (!context_) throw std::runtime_error(ErrorMessage());
243+
if (!context_) Nan::ThrowError(ErrorMessage());
244244
}
245245

246246
Context *
@@ -251,7 +251,10 @@ namespace zmq {
251251
void
252252
Context::Close() {
253253
if (context_ != NULL) {
254-
if (zmq_term(context_) < 0) throw std::runtime_error(ErrorMessage());
254+
if (zmq_term(context_) < 0) {
255+
Nan::ThrowError(ErrorMessage());
256+
return;
257+
}
255258
context_ = NULL;
256259
}
257260
}
@@ -371,8 +374,10 @@ namespace zmq {
371374
if (rc < 0) {
372375
if (zmq_errno()==EINTR) {
373376
continue;
377+
} else {
378+
Nan::ThrowError(ErrorMessage());
379+
return -1;
374380
}
375-
throw std::runtime_error(ErrorMessage());
376381
} else {
377382
break;
378383
}
@@ -983,12 +988,12 @@ namespace zmq {
983988
public:
984989
inline MessageReference() {
985990
if (zmq_msg_init(&msg_) < 0)
986-
throw std::runtime_error(ErrorMessage());
991+
Nan::ThrowError(ErrorMessage());
987992
}
988993

989994
inline ~MessageReference() {
990995
if (zmq_msg_close(&msg_) < 0)
991-
throw std::runtime_error(ErrorMessage());
996+
Nan::ThrowError(ErrorMessage());
992997
}
993998

994999
inline operator zmq_msg_t*() {
@@ -1055,8 +1060,10 @@ namespace zmq {
10551060
zmq_socket_monitor(this->socket_, NULL, ZMQ_EVENT_ALL);
10561061

10571062
// Close the monitor socket and stop timer
1058-
if (zmq_close(this->monitor_socket_) < 0)
1059-
throw std::runtime_error(ErrorMessage());
1063+
if (zmq_close(this->monitor_socket_) < 0) {
1064+
Nan::ThrowError(ErrorMessage());
1065+
return;
1066+
}
10601067
uv_timer_stop(this->monitor_handle_);
10611068
this->monitor_handle_ = NULL;
10621069
this->monitor_socket_ = NULL;
@@ -1188,13 +1195,13 @@ namespace zmq {
11881195
if (zmq_msg_init_data(&msg_, Buffer::Data(buf), Buffer::Length(buf),
11891196
BufferReference::FreeCallback, bufref_) < 0) {
11901197
delete bufref_;
1191-
throw std::runtime_error(ErrorMessage());
1198+
Nan::ThrowError(ErrorMessage());
11921199
}
11931200
};
11941201

11951202
inline ~OutgoingMessage() {
11961203
if (zmq_msg_close(&msg_) < 0)
1197-
throw std::runtime_error(ErrorMessage());
1204+
Nan::ThrowError(ErrorMessage());
11981205
};
11991206

12001207
inline operator zmq_msg_t*() {
@@ -1393,8 +1400,10 @@ namespace zmq {
13931400
void
13941401
Socket::Close() {
13951402
if (socket_) {
1396-
if (zmq_close(socket_) < 0)
1397-
throw std::runtime_error(ErrorMessage());
1403+
if (zmq_close(socket_) < 0) {
1404+
Nan::ThrowError(ErrorMessage());
1405+
return;
1406+
}
13981407
socket_ = NULL;
13991408
state_ = STATE_CLOSED;
14001409
context_.Reset();

0 commit comments

Comments
 (0)