[SERVER-5990] Extending Exception and Error Handling Created: 01/Jun/12 Updated: 25/Oct/21 Resolved: 25/Oct/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Diagnostics, JavaScript, Stability |
| Affects Version/s: | None |
| Fix Version/s: | features we're not sure of |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Nas Kavian | Assignee: | Geert Bosch |
| Resolution: | Won't Do | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
All |
||
| Participants: |
| Description |
|
JavaScript within a browser and Node.js have concepts of error handling and exception handling. Need mongo to provide similar support for error/exception handling. A very trivial example: when running a cron to execute a script; I need any JavaScript syntax errors captured by my custom code. If mongo says a query was invalid, I need that also captured by my code so I can log it with contextual details. |
| Comments |
| Comment by Nas Kavian [ 01/Jun/12 ] |
|
Using try/catch is valid, but it requires all developers to wrap 100% of everything they write. If they miss one spot then we're back to the same problem > try { foo(); } catch(e) {} Granted, if try/catch is not used; we will not get the benefit of recovering within the catch; but that's okay/expected. Instead of: Something like this would be great: mongo.onerror = function(message,file,line,stack) { .... } ; |
| Comment by Tad Marshall [ 01/Jun/12 ] |
|
You can use try/catch/throw in JavaScript in the shell to control error handling, depending on what you consider "errors". You can exit the shell with an error code with quit(exitCode) to pass status to cron. Does this get you started? Not everything that you might consider an error will throw JavaScript exceptions; for example, not finding a document that you query for is not an error from MongoDB's perspective, but you could throw an exception from your own code if that is an error for your logic. |