diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-08-18 10:23:56 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-08-18 10:23:56 -0400 |
commit | 39d0346def0c77ad56dd651baa6293475ae21be2 (patch) | |
tree | a96278d6b01bdc7b9f5a010faf4ec232810e3a0e /scripting | |
parent | 5663169f5fd6f0f1dbff0911455540ba7ca25400 (diff) | |
download | mongo-39d0346def0c77ad56dd651baa6293475ae21be2.tar.gz |
clean up cursor exception handling
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/sm_db.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp index f1e6244aec8..71b5b95fd42 100644 --- a/scripting/sm_db.cpp +++ b/scripting/sm_db.cpp @@ -95,7 +95,13 @@ namespace mongo { JSBool internal_cursor_hasNext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){ DBClientCursor *cursor = getCursor( cx, obj ); - *rval = cursor->more() ? JSVAL_TRUE : JSVAL_FALSE; + try { + *rval = cursor->more() ? JSVAL_TRUE : JSVAL_FALSE; + } + catch ( std::exception& e ){ + JS_ReportError( cx , e.what() ); + return JS_FALSE; + } return JS_TRUE; } @@ -108,13 +114,23 @@ namespace mongo { JSBool internal_cursor_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){ DBClientCursor *cursor = getCursor( cx, obj ); - if ( ! cursor->more() ){ - JS_ReportError( cx , "cursor at the end" ); + + BSONObj n; + + try { + if ( ! cursor->more() ){ + JS_ReportError( cx , "cursor at the end" ); + return JS_FALSE; + } + + n = cursor->next(); + } + catch ( std::exception& e ){ + JS_ReportError( cx , e.what() ); return JS_FALSE; } - Convertor c(cx); - BSONObj n = cursor->next(); + Convertor c(cx); *rval = c.toval( &n ); return JS_TRUE; } |