Skip to content

Commit

Permalink
Try Catch refactor for android support.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsthorpe742 committed May 25, 2017
1 parent 029e816 commit 7549c0e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
16 changes: 10 additions & 6 deletions python/common/org/python/types/Bytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,17 +484,21 @@ public org.python.Object __getitem__(org.python.Object index) {
} else if (index instanceof org.python.types.Bool || index instanceof org.python.types.Int) {
return this.__getitem__index(index);
} else {
org.python.Object index_object;
org.python.Object index_object = null;
boolean error_caught = false;
try {
index_object = index.__index__();
} catch (org.python.exceptions.TypeError | org.python.exceptions.AttributeError error) {
} catch (org.python.exceptions.TypeError error) {
error_caught = true;
} catch (org.python.exceptions.AttributeError error) {
error_caught = true;
}
if (error_caught) {
String message = "byte indices must be integers or slices, not " + index.typeName();
if (org.Python.VERSION < 0x03050000) {
throw new org.python.exceptions.TypeError("byte indices must be integers, not " + index.typeName());
} else {
throw new org.python.exceptions.TypeError(
"byte indices must be integers or slices, not " + index.typeName()
);
}
throw new org.python.exceptions.TypeError(message);
}
if (index_object instanceof org.python.types.Int) {
return this.__getitem__index(index);
Expand Down
30 changes: 24 additions & 6 deletions python/common/org/python/types/Slice.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ public Slice(org.python.Object start, org.python.Object stop, org.python.Object
} else if (start instanceof org.python.types.NoneType) {
this.__dict__.put("start", start);
} else {
org.python.Object index_object;
org.python.Object index_object = null;
boolean error_caught = false;
try {
index_object = start.__index__();
} catch (org.python.exceptions.TypeError | org.python.exceptions.AttributeError error) {
} catch (org.python.exceptions.TypeError error) {
error_caught = true;
} catch (org.python.exceptions.AttributeError error) {
error_caught = true;
}
if (error_caught) {
throw new org.python.exceptions.TypeError("slice indices must be integers or None or have an __index__ method");
}
if (index_object instanceof org.python.types.Int) {
Expand All @@ -41,10 +47,16 @@ public Slice(org.python.Object start, org.python.Object stop, org.python.Object
} else if (stop instanceof org.python.types.NoneType) {
this.__dict__.put("stop", stop);
} else {
org.python.Object index_object;
org.python.Object index_object = null;
boolean error_caught = false;
try {
index_object = stop.__index__();
} catch (org.python.exceptions.TypeError | org.python.exceptions.AttributeError error) {
} catch (org.python.exceptions.TypeError error) {
error_caught = true;
} catch (org.python.exceptions.AttributeError error) {
error_caught = true;
}
if (error_caught) {
throw new org.python.exceptions.TypeError("slice indices must be integers or None or have an __index__ method");
}
if (index_object instanceof org.python.types.Int) {
Expand All @@ -65,10 +77,16 @@ public Slice(org.python.Object start, org.python.Object stop, org.python.Object
} else if (step instanceof org.python.types.NoneType) {
this.__dict__.put("step", step);
} else {
org.python.Object index_object;
org.python.Object index_object = null;
boolean error_caught = false;
try {
index_object = step.__index__();
} catch (org.python.exceptions.TypeError | org.python.exceptions.AttributeError error) {
} catch (org.python.exceptions.TypeError error) {
error_caught = true;
} catch (org.python.exceptions.AttributeError error) {
error_caught = true;
}
if (error_caught) {
throw new org.python.exceptions.TypeError("slice indices must be integers or None or have an __index__ method");
}
if (index_object instanceof org.python.types.Int) {
Expand Down

0 comments on commit 7549c0e

Please sign in to comment.