<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _write_property(self, val, *args):
 """Sets the value of property. Given val is transformed accodingly to prop_write function when specified at construction-time. A try to cast the value to the property type is given."""

        val_wid = val
        # 'finally' would be better here, but not supported in 2.4 :(
        try:
            totype = type(self._get_property(*args))
            if (totype is not type(None) and
                   (self._prop_cast or not self._prop_write)):
                val = self._cast_value(val, totype)

            if self._prop_write:
                val = self._prop_write(val)

            self._itsme = True
            self._set_property(val, *args)

        except ValueError:
            self._itsme = False
            if self._value_error:
                self._value_error(self, self._prop_name, val_wid)
            else:
                raise

        except:
            self._itsme = False
            raise

        self._itsme = False