Do Phobos (and/or Tango) have a set of predefined exception types?
Asked Answered
I

2

5

The D documentation seems to be a bit messy, and I'm not able to find this information anywhere on the official site. I'm needing some common exception types (e.g. NotFiniteNumberException, FileIOException, types like that), do these exist in the core libraries, or would I have to roll these myself?

Indented answered 20/5, 2011 at 8:0 Comment(0)
G
7

Some of them exist, some of them don't. The best strategy to find them is to just do a global search look for the text : Exception in the D runtime (and Phobos), and seeing what all the preexisting exceptions are.

Most likely, though, you'll have to roll out at least some of your own.

What I found through this search were the following:

druntime\src\core\demangle.d(72):static class ParseException : Exception
druntime\src\core\demangle.d(81):static class OverflowException : Exception
druntime\src\core\exception.d(297):     class UnicodeException : Exception
druntime\src\core\thread.d(34):         class ThreadException : Exception
druntime\src\core\thread.d(51):         class FiberException : Exception
druntime\src\core\time.d(2703):         class TimeException : Exception
druntime\src\core\sync\exception.d(21): class SyncException : Exception
phobos\std\boxer.d(511):                class UnboxException : Exception
phobos\std\concurrency.d(198):          class MessageMismatch : Exception
phobos\std\concurrency.d(210):          class OwnerTerminated : Exception
phobos\std\concurrency.d(225):          class LinkTerminated : Exception
phobos\std\concurrency.d(240):          class PriorityMessageException: Exception
phobos\std\concurrency.d(255):          class MailboxFull : Exception
phobos\std\conv.d(33):                  class ConvException : Exception
phobos\std\demangle.d(26):      private class MangleException : Exception
phobos\std\encoding.d(2056):            class EncodingException : Exception
phobos\std\exception.d(792):            class ErrnoException : Exception
phobos\std\file.d(183):                 class FileException : Exception
phobos\std\json.d(418):                 class JSONException : Exception
phobos\std\regexp.d(161):               class RegExpException : Exception
phobos\std\socket.d(121):               class SocketException: Exception
phobos\std\socket.d(455):               class HostException: Exception
phobos\std\socket.d(670):               class AddressException: Exception
phobos\std\stdio.d(2111):               class StdioException : Exception
phobos\std\stream.d(44):                class StreamException: Exception
phobos\std\utf.d(45):                   class UtfException : Exception
phobos\std\variant.d(1153):      static class VariantException : Exception
phobos\std\xml.d(2726):                 class XMLException : Exception
phobos\std\zip.d(44):                   class ZipException : Exception
phobos\std\zlib.d(42):                  class ZlibException : Exception
phobos\std\windows\registry.d(75):      class Win32Exception : Exception

(Of course, if there are exceptions that inherit from classes other than Exception, or if there spacing was weird, then they're not on this list.)

Gregoor answered 20/5, 2011 at 8:3 Comment(1)
The general setup in druntime and Phobos is to create an exception specific to the module that it's thrown from (though in some cases, there are additional exception types for specific types of errors), and in general, you probably shouldn't be throwing exceptions of those types yourself. You generally can if you want to, but it could be confusing to anyone using your code when it starts throwing exceptions specific to standard library modules, and the exception didn't come from the standard library at all.Haya
M
3

The exception hierarchy was given quite some thought in Tango, and a general set is available from tango.core.Exception.

The more specialized your exception is, the less likely are you to find it there, but the intention was that all exceptions should make sense as subclasses to the existing exceptions.

Merodach answered 20/5, 2011 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.