Skip to content

Commit a5acabc

Browse files
committed
Use exception for error handling
1 parent 52a7921 commit a5acabc

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

app/deepseg.cc

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,9 @@ class CalcMask final {
231231
size_t height) :
232232
state{thread_state::INIT},
233233
thread{&CalcMask::run, this} {
234-
maskctx = bs_maskgen_new(
235-
modelname,
236-
threads,
237-
width,
238-
height,
239-
nullptr,
240-
onprep,
241-
oninfer,
242-
onmask,
243-
this
244-
);
234+
maskctx = bs_maskgen_new(modelname,threads,width,height,nullptr,onprep,oninfer,onmask,this);
245235
if (!maskctx)
246-
exit(1);
236+
throw "Could not create mask context";
247237

248238
// Do all other initialization …
249239
frame_next = &frame1;
@@ -277,7 +267,7 @@ class CalcMask final {
277267
}
278268
};
279269

280-
int main(int argc, char* argv[]) {
270+
int main(int argc, char* argv[]) try {
281271

282272
printf("deepseg version %s\n", _STR(DEEPSEG_VERSION));
283273
printf("(c) 2021 by [email protected] & contributors\n");
@@ -530,7 +520,7 @@ int main(int argc, char* argv[]) {
530520

531521
// timing details..
532522
printf("main [grab:%9ld retr:%9ld copy:%9ld prep:%9ld mask:%9ld post:%9ld v4l2:%9ld FPS: %5.2f] ai: [wait:%9ld prep:%9ld tflt:%9ld mask:%9ld FPS: %5.2f] \e[K\r",
533-
diffnanosecs(ti.grabns, ti.lastns),
523+
diffnanosecs(ti.grabns,ti.lastns),
534524
diffnanosecs(ti.retrns,ti.grabns),
535525
diffnanosecs(ti.copyns,ti.retrns),
536526
diffnanosecs(ti.prepns,ti.copyns),
@@ -571,4 +561,7 @@ int main(int argc, char* argv[]) {
571561

572562
printf("\n");
573563
return 0;
564+
} catch(const char* msg) {
565+
fprintf(stderr, "Error: %s\n", msg);
566+
return 1;
574567
}

0 commit comments

Comments
 (0)