digitalmars.D.learn - Exception: constructor arguments?
- mimocrocodil (5/5) Aug 14 2011 Where I can find description of Exception class?
- Johannes Pfau (15/20) Aug 14 2011 The Exception class is defined in druntime's object.d (as object.d is
- mimocrocodil (8/8) Aug 14 2011 Johannes Pfau: thanks!
- Jonathan M Davis (24/38) Aug 14 2011 Then give null for the message value. Usually, it's a _bad_ thing not to...
Where I can find description of Exception class? I seen this URLs, but they do not contain this information: http://www.d-programming-language.org/phobos/std_exception.html http://www.d-programming-language.org/phobos/core_exception.html http://www.d-programming-language.org/errors.html
Aug 14 2011
mimocrocodil wrote:Where I can find description of Exception class? I seen this URLs, but they do not contain this information: http://www.d-programming-language.org/phobos/std_exception.html http://www.d-programming-language.org/phobos/core_exception.html http://www.d-programming-language.org/errors.htmlThe Exception class is defined in druntime's object.d (as object.d is automatically imported). The API documentation for object is here: http://www.d-programming-language.org/phobos/object.html I think there's no link for it in the side-bar. I found it by guessing :-) However, there's almost no documentation for Throwable and Exception, so you may want to have a look at the source code: Throwable: https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L1225 Exception: https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L1328 -- Johannes Pfau
Aug 14 2011
Johannes Pfau: thanks! Next question: Why do we always have to send a text message with a standard class of Exception? After all, it might be never used, for example due to the fact that error messages are not sent to the user "as is": exception can be analyzed and translated for internationalization, for example. Is it right way that the standard library forces user to store error msg and, in general, leads to inefficient memory usage. (No, I'm not kidding! I'm worried about the design. :) )
Aug 14 2011
On Sunday, August 14, 2011 15:48:36 mimocrocodil wrote:Johannes Pfau: thanks! Next question: Why do we always have to send a text message with a standard class of Exception? After all, it might be never used, for example due to the fact that error messages are not sent to the user "as is": exception can be analyzed and translated for internationalization, for example. Is it right way that the standard library forces user to store error msg and, in general, leads to inefficient memory usage. (No, I'm not kidding! I'm worried about the design. :) )Then give null for the message value. Usually, it's a _bad_ thing not to have a message, because it makes it harder to figuree out what happened. So, from the standpoint of Exception actually working well as an error-handling mechanism, it's better to require a message rather than defaulting to none. Also, on some level, _it doesn't matter if Exception has inefficient memory usage_. Exceptions are _expected_ to be slower than normal code. They are used when something goes wrong. They are _way_ slower than normal code - so much so that a string is going to have pretty much zero effect on efficiency one way or the other. It would be nice if they were made to be more efficient so that unit tests weren't so slow when you checked to make sure that the proper exception is thrown when it's supposed to for a function, but for normal code, it doesn't really matter much. It would be nice if they were faster, but since they're supposed to be exceptional, it's not all that big a deal. Exceptions are slow in every language that I've ever used. Now, they're a lot faster in Java than D, and as I said, it would be nice if they were faster for at least unit testing purposes, but expect exceptions to be slow. Efficiency is _not_ a primary concern of exceptions. So, if you really want to avoid the memory allocation for the message, just pass it null, but don't expect it to have any real impact on the efficiency of exceptions. Exceptions are slow by their very nature. They could be faster than they are, but no matter what we do, the plumbing required to make exceptions work makes them far slower than normal code. - Jonathan M Davis
Aug 14 2011