www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: rtti cast

reply terranium <spam here.lot> writes:
downs Wrote:

 As such, an exception (which is reserved, appropriately, for *exceptional*
events), is totally the wrong approach to use.
 

 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.
 

May 07 2008
parent BCS <BCS pathlink.com> writes:
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 {} }
May 07 2008