November 16, 2021
On 11/16/21 12:30 AM, bauss wrote:
> On Monday, 15 November 2021 at 22:44:35 UTC, Ali Çehreli wrote:
>> On 11/15/21 2:28 PM, pascal111 wrote:
>> > I want to know where the list of exceptions names that
>> "throw" statement
>> > uses.
>>
>> Such a list is not very useful. Normally all we need is Exception and
>> occasionally one or two other specific types.
>>
>
> It's actually very useful when you want to throw exceptions yourself,

That's very different from how I use exceptions perhaps because mine have been command line tools. I would love to learn more about how others use exceptions.

The existing exception type that I reuse is Exception :), which I throw indirectly by enforce:

  enforce(isOk, format!"There is a problem with %s"(x));

I even convert a ConvException that I catch to Exception with the same method just to give a little bit of more

  catch (ConvException ex) {
    enforce(false,
      format!"Failed to parse '%s' as blah: %s"(y, ex.msg));
  }

That shows how lazy I am. :)

> because instead of writing your own custom exception then you could use
> an existing implementation.

Unless there are standardized exceptions, that feels weird to me because such reused exceptions may have constructor parameters which may not make sense where I throw that exception.

Luckily, there is basicExceptionCtors, which trivializes implementing exception types anyway. For example, I copied the following from /usr/include/dmd/phobos/std/conv.d:

class ConvException : Exception
{
    import std.exception : basicExceptionCtors;
    ///
    mixin basicExceptionCtors;
}

Further, it doesn't feel right to throw e.g. std.conv.ConvException from my foo.bar module. The cases where another module's exception fitting my use closely feels so rare that I wouldn't even think about reaching for an existing exception of another module or a library.

I don't know... That's my comfortable and lazy use of exceptions. :)

Ali


November 16, 2021

On Tuesday, 16 November 2021 at 09:29:34 UTC, Ali Çehreli wrote:

>

Further, it doesn't feel right to throw e.g. std.conv.ConvException from my foo.bar module. The cases where another module's exception fitting my use closely feels so rare that I wouldn't even think about reaching for an existing exception of another module or a library.

I think it is a mistake for std to not collect all exceptions in one location. If you want to write a library that is a natural extension of the standard library then you also want to follow the same error handling pattern so that user code can replace a standard library function with an enhanced third party function without changing the error handling code down the call-tree.

November 16, 2021

On Tuesday, 16 November 2021 at 00:10:44 UTC, Imperatorn wrote:

>

On Tuesday, 16 November 2021 at 00:05:45 UTC, Imperatorn wrote:

>

On Tuesday, 16 November 2021 at 00:03:14 UTC, Imperatorn wrote:

>

On Monday, 15 November 2021 at 22:55:55 UTC, pascal111 wrote:

>

On Monday, 15 November 2021 at 22:39:36 UTC, Imperatorn wrote:

>

On Monday, 15 November 2021 at 22:28:28 UTC, pascal111 wrote:

>

I want to know where the list of exceptions names that "throw" statement uses. I searched in dlang site, and google but couldn't reach it.

Just so I understand, do you mean a list similar to this?
https://www.completecsharptutorial.com/basic/complete-system-exception.php

Exactly!

You can begin here:
https://dlang.org/phobos/core_exception.html

If there is no such similar list we should create one.

I just did a quick grep of phobos and matched the derived exceptions and got this:
Base64Exception
MessageMismatch
OwnerTerminated
LinkTerminated
PriorityMessageException
MailboxFull
TidMissingException
ConvException
CSVException
EncodingException
MeaCulpa
E2
E3
E
ErrnoException
TestException
FileException
GetOptException
MyEx
JSONException
ProcessException
StdioException
StringException
MatchException
URIException
UUIDParsingException
VariantException
XMLException
ZipException
ZlibException
CheckFailure
FormatException
CurlException
RegexException
WindowsException

Here are some guides to follow if you want (and that we can learn from in D):

https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/using-standard-exception-types

https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/exception-throwing

https://docs.microsoft.com/en-us/dotnet/standard/exceptions/best-practices-for-exceptions

https://docs.microsoft.com/en-us/dotnet/standard/exceptions/

https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/exceptions/creating-and-throwing-exceptions

November 16, 2021

On Tuesday, 16 November 2021 at 09:41:15 UTC, Ola Fosheim Grøstad wrote:

>

want to follow the same error handling pattern so that user code can replace a standard library function with an enhanced third party function without changing the error handling code down the call-tree.

Eh, up the call-tree. Why are call-trees upside-down?

November 16, 2021

On Tuesday, 16 November 2021 at 10:28:18 UTC, Imperatorn wrote:

> >

I just did a quick grep of phobos and matched the derived exceptions and got this:
Base64Exception
MessageMismatch
OwnerTerminated
LinkTerminated
PriorityMessageException
MailboxFull
TidMissingException
ConvException
CSVException
EncodingException

Neat list. I guess a few of them are template-parameter names?

But yeah, the list shows that there is an ontology-job that ought to be done. Naming-schemes and making sure that the most specific exceptions subclass more generic ones, I guess.

November 16, 2021

On Tuesday, 16 November 2021 at 11:54:43 UTC, Ola Fosheim Grøstad wrote:

>

On Tuesday, 16 November 2021 at 10:28:18 UTC, Imperatorn wrote:

> >

I just did a quick grep of phobos and matched the derived exceptions and got this:
Base64Exception
MessageMismatch
OwnerTerminated
LinkTerminated
PriorityMessageException
MailboxFull
TidMissingException
ConvException
CSVException
EncodingException

Neat list. I guess a few of them are template-parameter names?

But yeah, the list shows that there is an ontology-job that ought to be done. Naming-schemes and making sure that the most specific exceptions subclass more generic ones, I guess.

Yeah, those are really ugly :D

1 2
Next ›   Last »