Exception Handling #64

Merged
merged 12 commits into from Aug 21, 2016

Projects

None yet

4 participants

@rajithv
Contributor
rajithv commented Jul 23, 2016

An example with cbasic_div method.

rajithv added some commits Jul 23, 2016
@rajithv rajithv Init exception handling
fdae674
@rajithv rajithv Fixed minor memory leak
8cf9e08
@rajithv rajithv Error handling for unary and binary operations, one arg and two arg f…
…unctions
9fbfcd8
@v0dro v0dro and 1 other commented on an outdated diff Jul 24, 2016
ext/symengine/ruby_basic.c
- return result;
+ int error_code = cwfunc_ptr(cresult, this, cbasic_operand2);
+ if (error_code == 0) {
+ result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL,
+ cbasic_free_heap, cresult);
+ basic_free_stack(cbasic_operand2);
+ return result;
+ } else {
+ basic_free_stack(cbasic_operand2);
+ rb_raise(rb_eRuntimeError, "Runtime Error");
@v0dro
v0dro Jul 24, 2016

What does this error signify? The error message should be more descriptive than "Runtime Error", which does not give much information about what's actually going wrong.

@rajithv
rajithv Jul 24, 2016 Contributor

@v0dro this is in place until a exceptions are made in the SymEngine C++ code (right now it's all std::runtime_errors). Anyway I have written the code to be integrated into the cwrappers to catch multiple exceptions (for a method like parse this is needed). Then depending on the error code sent, the suitable error message will be displayed. This is still WIP. Please check symengine/symengine#1044 for the discussion on this :)

rajithv added some commits Jul 25, 2016
@rajithv rajithv Different Exceptions added
c61c08e
@rajithv rajithv Functions Spec Tests
52236c6
@isuruf isuruf commented on an outdated diff Aug 16, 2016
ext/symengine/symengine_utils.c
- result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap,
- cresult);
- basic_free_stack(cbasic_operand1);
- basic_free_stack(cbasic_operand2);
+ int error_code = cwfunc_ptr(cresult, cbasic_operand1, cbasic_operand2);
+
+ if (error_code == 0) {
+ result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL,
+ cbasic_free_heap, cresult);
+ basic_free_stack(cbasic_operand1);
+ basic_free_stack(cbasic_operand2);
+ return result;
+ } else {
+ basic_free_stack(cbasic_operand1);
+ basic_free_stack(cbasic_operand2);
+ rb_raise(rb_eRuntimeError, "Runtime Error");
@isuruf
isuruf Aug 16, 2016 Member

You should use raise_exception here.

@isuruf isuruf commented on an outdated diff Aug 16, 2016
ext/symengine/symengine_utils.c
- return result;
+void raise_exception(int error_code)
+{
+ char *str;
+ switch (error_code) {
+ case -1:
@isuruf
isuruf Aug 16, 2016 Member

Use the enums here, without using ints

@isuruf isuruf commented on an outdated diff Aug 16, 2016
ext/symengine/symengine_utils.h
VALUE operand1);
// Returns the result from the function pointed by cwfunc_ptr: for two argument
// functions
-VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct *, const basic_struct *,
- const basic_struct *),
+VALUE function_twoarg(int (*cwfunc_ptr)(basic_struct *, const basic_struct *,
@isuruf
isuruf Aug 16, 2016 Member

Use CWRAPPER_OUTPUT_TYPE instead of int here.

rajithv added some commits Aug 16, 2016
@rajithv rajithv Merge branch 'master' of https://github.com/symengine/symengine.rb in…
…to exception
acfd1f3
@rajithv rajithv Changes to symengine_utils
4e64375
@isuruf isuruf commented on an outdated diff Aug 17, 2016
ext/symengine/symengine_utils.c
+ if (error_code == 0) {
@isuruf
isuruf Aug 17, 2016 Member

Instead of 0, check for SYMENGINE_NO_EXCEPTION

@isuruf
Member
isuruf commented Aug 17, 2016

Can you add some tests in ruby?

rajithv added some commits Aug 19, 2016
@rajithv rajithv Test for Division By Zero
c5205a2
@rajithv rajithv Division by Zero tests for trig functions
09553f1
@abinashmeher999 abinashmeher999 commented on an outdated diff Aug 19, 2016
ext/symengine/ruby_basic.c
+ int error_code = cwfunc_ptr(cresult, this, cbasic_operand2);
@abinashmeher999
abinashmeher999 Aug 19, 2016 Contributor

Try to use the enum for error codes here.

@rajithv rajithv Changed int to enum type for error code
2ada844
@isuruf isuruf commented on the diff Aug 19, 2016
ext/symengine/ruby_basic.c
+ symengine_exceptions_t error_code = cwfunc_ptr(cresult, this);
@isuruf
isuruf Aug 19, 2016 Member

You should use one convention. int or symengine_exceptions_t or CWRAPPER_OUTPUT_TYPE. All 3 are used in this PR.

@rajithv rajithv Changed all instances of error codes to symengine_exceptions_t
c5f755a
@rajithv rajithv changed the title from [WIP] Exception Handling to Exception Handling Aug 19, 2016
@rajithv rajithv Update symengine version and adapt changes to basic_diff
7de5e6d
@isuruf isuruf merged commit eed5f42 into symengine:master Aug 21, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@isuruf
Member
isuruf commented Aug 21, 2016

Thanks for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment