Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MXNET-1357] Fix the cpp-examples to add exception handling #14441

Merged
merged 3 commits into from
Apr 2, 2019

Conversation

leleamol
Copy link
Contributor

Description

The scope of this PR is to add missing exception handling to the examples. In future, if the underlying MXNet code throws any exception, the example will catch this exception and fail gracefully instead of crashing due to unhandled exception.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • [y] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • [y] Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • [y] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@leleamol leleamol requested a review from nswamy as a code owner March 15, 2019 21:12
@leleamol
Copy link
Contributor Author

@anirudh2290

@leleamol
Copy link
Contributor Author

#14406

@@ -228,6 +228,7 @@ int main(int argc, char const *argv[]) {
}
#endif

TRY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just add exception handling to cpp-package the way it is done in python. Every C API call is inside a check_call function which checks the return code and throws corresponding frontend exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is certainly possible to add exception handling in cpp-package API itself. However, it will require careful design and we may require to change the cpp-package API as well.
We will certainly consider this enhancement as a part of C++ API enhancement project.

@karan6181
Copy link
Contributor

@mxnet-label-bot add [C++, Example, Exception Handling, pr-awaiting-response ]

@marcoabreu marcoabreu added C++ Related to C++ Example Exception Handling pr-awaiting-response PR is reviewed and waiting for contributor to respond labels Mar 15, 2019
@leleamol
Copy link
Contributor Author

@mxnet-jenkins The unix-cpu and unix-gpu build failures are not related to the changes in PR.
Can we restart these builds?

try {
#define CATCH \
} catch(...) { \
LG << "Status: FAIL";\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch only dmlc::Error. For non backend exceptions MXGetLastError will be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

LG << "Status: FAIL";\
LG << "With Error: " << MXGetLastError(); \
return 1; \
} catch(...) { \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you should only have dmlc::Error catch and remove the catch all. If there is any other exception thrown it could be because of some MXNet backend showing non dmlc::Errors (which is very unlikely) or some other exception thrown from the example code because of user or programming error. Users should be able to see what these exceptions are without having to modify utils.

@piyushghai
Copy link
Contributor

@anirudh2290 Are you comments addressed now in this PR ?

Copy link
Member

@anirudh2290 anirudh2290 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@anirudh2290 anirudh2290 merged commit 9e4ee99 into apache:master Apr 2, 2019
ZhennanQin pushed a commit to ZhennanQin/incubator-mxnet that referenced this pull request Apr 3, 2019
…4441)

* Adding exception handling to the cpp-package examples.

* Updating exception handling to catch dmlc::error.

* Removed the catch all exception.
nswamy pushed a commit that referenced this pull request Apr 5, 2019
* Adding exception handling to the cpp-package examples.

* Updating exception handling to catch dmlc::error.

* Removed the catch all exception.
@leleamol leleamol deleted the cpp-examples branch June 10, 2019 18:10
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
…4441)

* Adding exception handling to the cpp-package examples.

* Updating exception handling to catch dmlc::error.

* Removed the catch all exception.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C++ Related to C++ Example Exception Handling pr-awaiting-response PR is reviewed and waiting for contributor to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants