Skip to content
Permalink
Browse files

Clean up pass on exceptions.

  • Loading branch information...
Thrameos committed May 31, 2019
1 parent dd4954d commit ffd9690661cc2ecb6dc76978bf130244be87b1f7
@@ -89,7 +89,7 @@ void JPArray::setRange(jsize start, jsize stop, PyObject* val)
// the length of the array. But java arrays are immutable in length.
std::stringstream out;
out << "Slice assignment must be of equal lengths : " << len << " != " << plength;
JP_RAISE_RUNTIME_ERROR(out.str());
JP_RAISE_VALUE_ERROR(out.str());
}

JP_TRACE("Call component set range");
@@ -111,7 +111,7 @@ void JPArray::setItem(jsize ndx, PyObject* val)

if (compType->canConvertToJava(val) <= JPMatch::_explicit)
{
JP_RAISE_RUNTIME_ERROR("Unable to convert.");
JP_RAISE_TYPE_ERROR("Unable to convert.");
}

compType->setArrayItem(frame, m_Object.get(), ndx, val);
@@ -48,7 +48,7 @@ jobject JPByteType::convertToDirectBuffer(PyObject* src)
return frame.keep(frame.NewDirectByteBuffer(rawData, size));
}

JP_RAISE_RUNTIME_ERROR("Unable to convert to Direct Buffer");
JP_RAISE_TYPE_ERROR("Unable to convert to Direct Buffer");
JP_TRACE_OUT;
}

@@ -70,7 +70,7 @@ void JPField::setStaticField(PyObject* val)
{
stringstream err;
err << "Field " << m_Name << " is read-only";
JP_RAISE_RUNTIME_ERROR(err.str().c_str());
JP_RAISE_ATTRIBUTE_ERROR(err.str().c_str());
}

if (m_TypeCache->canConvertToJava(val) <= JPMatch::_explicit)
@@ -105,7 +105,7 @@ void JPField::setField(jobject inst, PyObject* val)
{
stringstream err;
err << "Field " << m_Name << " is read-only";
JP_RAISE_RUNTIME_ERROR(err.str().c_str());
JP_RAISE_ATTRIBUTE_ERROR(err.str().c_str());
}

if (m_TypeCache->canConvertToJava(val) <= JPMatch::_explicit)
@@ -20,7 +20,11 @@ jobject JPValue::getJavaObject() const
{
if (dynamic_cast<JPPrimitiveType*> (m_Class) != m_Class)
return m_Value.l;
JP_RAISE_RUNTIME_ERROR("access primitive value as object");

// This method is only used internally, thus it requires a logical code
// error to trigger. We will use type error in case there is some
// way a user can trigger it.
JP_RAISE_TYPE_ERROR("access Java primitive value as Java object");
}

jclass JPValue::getJavaClass() const
@@ -154,6 +154,17 @@ def testJArrayConversionShort(self):
# with self.assertRaises(jpype._):
# jpype.JArray(jpype.JShort)([2**16/2])

def testJArrayConversionFail(self):
jarr = jpype.JArray(jpype.JInt)(self.VALUES)
with self.assertRaises(TypeError):
jarr[1] = 'a'

def testJArraySliceLength(self):
jarr = jpype.JArray(jpype.JInt)(self.VALUES)
jarr[1:2] = [1]
with self.assertRaises(ValueError):
jarr[1:2] = [1,2,3]

def testJArrayConversionInt(self):
jarr = jpype.JArray(jpype.JInt)(self.VALUES)
result = jarr[0: len(jarr)]

0 comments on commit ffd9690

Please sign in to comment.
You can’t perform that action at this time.