Originally posted by ultimA
View Post
Memory allocation can fail, but that's a killer in pretty much any language. Ok say in Java the program doesn't panic directly but you get an OutOfMemoryError... and then what? It crashes because it's basically the only thing that it can do. Same in C - malloc() would return NULL, and then you either abort(), or you pretend to handle it gracefully but you can't really, because with no more RAM available to the process, it can't do much anyway.
Downcasting can also fail, but again, it's not more frequent than in other languages. It would fail in pretty much the same cases as dynamic_cast<> would fail in C++. Casting from void* to some type in C obviously never fails, but that's not a good thing at all, except when it's used as a poor man's substitute for generics. In Rust you would obviously never use the "any" type for that.
Comment