Repository: FreeCAD/FreeCAD
File: src/Mod/Material/App/Array3DPyImp.cpp (C++)

Code before:
    int depth;
    if (!PyArg_ParseTuple(args, "i", &depth)) {
        return nullptr;
    }

    try {
        auto value = getArray3DPtr()->getDepthValue(depth);
        return new Base::QuantityPy(new Base::Quantity(value));
    }
    catch (const InvalidIndex&) {
    }

    PyErr_SetString(PyExc_IndexError, "Invalid array index");
    return nullptr;
}

PyObject* Array3DPy::setDepthValue(PyObject* args)
{
    int depth;
    PyObject* valueObj;
    if (PyArg_ParseTuple(args, "iO!", &depth, &PyUnicode_Type, &valueObj)) {
        Py::String item(valueObj);
        try {
            auto quantity = Base::Quantity::parse(item.as_string());
            quantity.setFormat(MaterialValue::getQuantityFormat());
            getArray3DPtr()->setDepthValue(depth, quantity);
        }
        catch (const InvalidIndex&) {
            PyErr_SetString(PyExc_IndexError, "Invalid array index");
            return nullptr;
        }
        Py_Return;
    }

    PyErr_SetString(PyExc_TypeError, "Expected (integer, string) arguments");
    return nullptr;
}

PyObject* Array3DPy::setValue(PyObject* args)
{
    int depth;
    int row;
    int column;
    PyObject* valueObj;
    if (PyArg_ParseTuple(args, "iiiO!", &depth, &row, &column, &PyUnicode_Type, &valueObj)) {
        Py::String item(valueObj);
        try {
            auto quantity = Base::Quantity::parse(item.as_string());
            quantity.setFormat(MaterialValue::getQuantityFormat());
            getArray3DPtr()->setValue(depth, row, column, quantity);
        }

Review comment (bug):
```suggestion
            getArray3DPtr()->setDepthValue(depth, quantity);
        }
        catch (const ParseError&) {
            PyErr_SetString(PyExc_ValueError, "Cannot parse value");
            return nullptr;
```

Code after:
    int depth;
    if (!PyArg_ParseTuple(args, "i", &depth)) {
        return nullptr;
    }

    try {
        auto value = getArray3DPtr()->getDepthValue(depth);
        return new Base::QuantityPy(new Base::Quantity(value));
    }
    catch (const InvalidIndex&) {
    }

    PyErr_SetString(PyExc_IndexError, "Invalid array index");
    return nullptr;
}

PyObject* Array3DPy::setDepthValue(PyObject* args)
{
    int depth;
    PyObject* valueObj;
    if (PyArg_ParseTuple(args, "iO!", &depth, &PyUnicode_Type, &valueObj)) {
        Py::String item(valueObj);
        try {
            auto quantity = Base::Quantity::parse(item.as_string());
            quantity.setFormat(MaterialValue::getQuantityFormat());
            getArray3DPtr()->setDepthValue(depth, quantity);
        }
        catch (const Base::ParserError& e) {
            PyErr_SetString(PyExc_ValueError, e.what());
            return nullptr;
        }
        catch (const InvalidIndex& e) {
            PyErr_SetString(PyExc_IndexError, e.what());
            return nullptr;
        }
        Py_Return;
    }

    PyErr_SetString(PyExc_TypeError, "Expected (integer, string) arguments");
    return nullptr;
}

PyObject* Array3DPy::setValue(PyObject* args)
{
    int depth;
    int row;
    int column;
    PyObject* valueObj;
    if (PyArg_ParseTuple(args, "iiiO!", &depth, &row, &column, &PyUnicode_Type, &valueObj)) {
        Py::String item(valueObj);
        try {