Skip to content

Commit 3d41d63

Browse files
committed
IOIO: tidy up error messages
1 parent e5c6d66 commit 3d41d63

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

ioio/main.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,23 @@ struct IOTask {
5151
_array = nullptr;
5252
}
5353

54-
bool create(const char *path) {
54+
bool create(const char *path, var_s *retval) {
5555
bool result;
5656
if (_instance != nullptr) {
57-
// error when already constructed
57+
error(retval, "Internal error - already constructed");
5858
result = false;
5959
} else {
6060
_clazz = env->FindClass(path);
61-
if (_clazz == nullptr) {
62-
env->ExceptionDescribe();
63-
} else {
61+
if (_clazz != nullptr) {
6462
jmethodID constructor = env->GetMethodID(_clazz, "<init>", "()V");
65-
if (constructor == nullptr) {
66-
env->ExceptionDescribe();
67-
} else {
63+
if (constructor != nullptr) {
6864
_instance = env->NewObject(_clazz, constructor);
6965
}
7066
}
7167
result = _instance != nullptr;
68+
if (!result) {
69+
checkException(retval);
70+
}
7271
}
7372
return result;
7473
}
@@ -431,7 +430,7 @@ int sblib_init(const char *sourceFile) {
431430
}
432431

433432
ioioTask = new IOTask();
434-
if (!ioioTask || !ioioTask->create(CLASS_IOIO)) {
433+
if (!ioioTask || !ioioTask->create(CLASS_IOIO, nullptr)) {
435434
fprintf(stderr, "Failed to IOIOTask\n");
436435
result = 0;
437436
}

ioio/mkapi.bas

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,13 @@ sub generate_open_function(byref obj)
116116
endif
117117
print " int id = ++nextId;"
118118
print " IOTask &instance = _ioTaskMap[id];"
119-
print " if (instance.create(CLASS_" + upper(obj.name) + ") &&"
119+
print " if (instance.create(CLASS_" + upper(obj.name) + ", retval) &&"
120120
print " instance." + openFunc + "retval)) {"
121121
print " map_init_id(retval, id, CLASS_IOTASK_ID);"
122122
print " create_" + lower(obj.name) + "(retval);"
123123
print " result = 1;"
124124
print " } else {"
125125
print " _ioTaskMap.erase(id);"
126-
print " error(retval, \"open" + obj.name + "() failed\");"
127126
print " result = 0;"
128127
print " }"
129128
print " return result;"

ioio/samples/bme280.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func bme280_init(t_mode, p_mode, h_mode, iir)
8080
result.H4 = (read8(0xE4) lshift 4) + (a mod 16)
8181
result.H5 = (read8(0xE6) lshift 4) + (a rshift 4)
8282
result.H6 = read8(0xE7)
83-
if H6 > 127 then result.H6 -= 256
83+
if result.H6 > 127 then result.H6 -= 256
8484

8585
write8(0xF2, h_mode)
8686
sleep_ms(10)

ioio/src/main/java/net/sourceforge/smallbasic/ioio/IOService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public void start() {
5959
private void registerPin(int pin) throws IOException {
6060
if (pin != -1) {
6161
if (pin < 0 || pin > MAX_PINS) {
62-
throw new IOException("invalid pin: " + pin);
62+
throw new IOException("Invalid pin: " + pin);
6363
}
6464
if (usedPins[pin] != null && usedPins[pin]) {
65-
throw new IOException("pin already used: " + pin);
65+
throw new IOException("Pin already used: " + pin);
6666
}
6767
usedPins[pin] = true;
6868
}

0 commit comments

Comments
 (0)