Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit bf6d2ae

Browse files
committed
feat(): add exception helpers
1 parent 99bfbb1 commit bf6d2ae

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ add_library(${PROJECT_NAME} SHARED
2727
"src/ng-test.cpp"
2828
"src/QWidgetWrap/qwidget_wrap.cpp"
2929
"src/utils.cpp"
30-
)
30+
"src/exceptions.cpp")
3131

3232
link_directories($ENV{QT_LIBRARIES})
3333

src/exceptions.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "exceptions.h"
2+
#include "napi.h"
3+
4+
void throwInvalidKeyException(const Napi::Env &env) {
5+
return Napi::TypeError::New(env, "argument key must be a string")
6+
.ThrowAsJavaScriptException();
7+
}
8+
9+
void throwInvalidArgumentsException(const Napi::Env &env) {
10+
return Napi::TypeError::New(env, "Wrong number of arguments")
11+
.ThrowAsJavaScriptException();
12+
}
13+
14+
void throwInvalidModifierException(const Napi::Env &env) {
15+
return Napi::TypeError::New(env, "argument modifier must be a number")
16+
.ThrowAsJavaScriptException();
17+
}
18+
19+
void throwInvalidDelayException(const Napi::Env &env) {
20+
return Napi::TypeError::New(env, "argument delay must be a number")
21+
.ThrowAsJavaScriptException();
22+
}

src/exceptions.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "napi.h"
2+
3+
void throwInvalidKeyException(const Napi::Env &env);
4+
5+
void throwInvalidArgumentsException(const Napi::Env &env);
6+
7+
void throwInvalidModifierException(const Napi::Env &env);
8+
9+
void throwInvalidDelayException(const Napi::Env &env);

0 commit comments

Comments
 (0)