thekid/rfc — Issue #85: RFC 0085: Make lang.Throwable::toString() easily overwriteable
Author: thekid
Created: 2011-10-09 14:57:53+00:00
State: closed
Labels: implemented, rfc

Scope of Change
====
A new method compoundMessage() will be added to lang.Throwable. It will
be called from toString().

Rationale
====
The lang.Throwable's toString() method is a mess to overwrite - for any
changes subclasses would like to make to the compound message (usually,
the word "Exception", the exception's fully-qualified classname and
message), they have to reimplement the stringification of the exception's
stack trace.

Functionality
====

Current (peer.http.UnexpectedResponseException)
----

```php
getClassName(),
$this->statuscode,
$this->message
);
for ($i= 0, $t= sizeof($this->trace); $i < $t; $i++) {
$s.= $this->trace[$i]->toString();
}
return $s;
}
?>
```
You can clearly see the boilerplate loop on the stack trace elements.

When this RFC is committed, the UnexpectedResponseException class would
not overwrite toString() but rather the new compoundMessage() method.

Refactored
----

```php
getClassName(),
$this->statuscode,
$this->message
);
}
?>
```

Of course, exception classes need not overwrite the compoundMessage()
method. The Throwable class provides the following default
implementation:

lang.Throwable::compoundMessage()
----

```php
getClassName(),
$this->message
);
}
?>
```

Security considerations
====
n/a

Speed impact
====
Slightly slower (one more method call).

Dependencies
====
n/a

Related documents
====
- http://xp-framework.net/rfc/contrib/rfc0085.diff
Patch implementing this RFC

- http://xp-framework.net/rfc/contrib/exceptions.diff
Patch to all exception classes

Comments
====