May 07, 2008 Re: rtti cast | ||||
|---|---|---|---|---|
| ||||
downs Wrote: > As such, an exception (which is reserved, appropriately, for *exceptional* events), is totally the wrong approach to use. > Yes, function received wrong input, this is normal, if we want, we throw exception, if we want, we ignore it. > Note that with the current behavior, you can incur the runtime speed loss of throwing an exception if you _want_ to, by using the above templated wrapper, but if throwing an exception were the only possibility, you couldn't possibly get that speed back. > You'll get that speed back without hours spent in debugger trying to figure out, "where this null came from"? | ||||
May 07, 2008 Re: rtti cast | ||||
|---|---|---|---|---|
| ||||
Posted in reply to terranium | terranium wrote:
> downs Wrote:
>
>
>>As such, an exception (which is reserved, appropriately, for *exceptional* events), is totally the wrong approach to use.
>>
>
> Yes, function received wrong input, this is normal, if we want, we throw exception, if we want, we ignore it.
>
The point is that offtent a failed cast is not an indecation of an error. For instance code like this
class A {}
class B1 : A {}
class B2 : A {}
void foo(A a)
{
if(auto b = cast(B1)a) {}
else if(auto b = cast(B2)a) {}
else {}
}
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply