ID:2006428
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
While exceptions and such are useful, I think there are ways to improve them a lot.

Part 1 of this feature request is native subtypes for exceptions. I don't mean the ability to define exception subtypes, because we can already do that.

What I mean is that there should be built in subtypes for exceptions. This will allow exceptions to be more easily handled by code, and allow more relevant data to be passed.

For example, if you were to catch an exception of a division by zero runtime, it'd have typepath /exception/divisionbyzero, a type-mismatch on the other hand would be /exception/typemismatch.

I understand that in most cases, this can be determined via code and string procs, but this is slow, and subtypes allow my next point: more data on exception datums.

For example, a type mismatch exception would contain both of the values that were involved in the mismatch. So if you did 10 + [reference], the exception caused by that would have a variable containing 10 and one containing [reference]. It would also have a string containing whatever operator was used in the mismatch.

It would also be nice if exceptions had actual references to src, usr, and others, right now they don't, and you can't even get a reference to do any reading of values on the objects involved (of course you can in a try-catch, but not in world/Error()).

A good example of why this would be useful:
In SS13, we have our own garbage collector, when it deletes an object, it sets the "gcDestroyed" variable on the object to 1. It would be useful to be able to add this to the runtime error message sent to world.log.
Native subtypes doesn't strike me as worth doing; it'd add a bunch of types that aren't needed for most purposes, especially when the type of exception can be gleaned via findtext(). References to usr and src might have some merit. For the type mismatches I think including the two values would probably be overkill.
A feature request for src/usr can be found here: http://www.byond.com/forum/?post=1953525

and a bug that limits adding your own data to exceptions:
http://www.byond.com/forum/?post=1958074