www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Exceptions names list

reply pascal111 <judas.the.messiah.111 gmail.com> writes:
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.
Nov 15 2021
next sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
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
Nov 15 2021
parent reply pascal111 <judas.the.messiah.111 gmail.com> writes:
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!
Nov 15 2021
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
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
Nov 15 2021
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
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.
Nov 15 2021
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
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
Nov 15 2021
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
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
Nov 16 2021
parent reply Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= <ola.fosheim.grostad gmail.com> writes:
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.
Nov 16 2021
parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
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
Nov 16 2021
prev sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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. There can be hundreds of specific types of Exception a program may throw, sometimes unknowingly by calling a library that it uses. That list can change dramatically simply by adding a single line to the program. (That line may call a new module and that module may throw dozens of different Exception types.) What matters is they are all Exceptions. So, most of the time all one needs to do is to catch Exception in main and be done with it: int main() { try { work(); } catch (Exception ex) { stderr.writefln!"ERROR: %s"(ex.msg); return 1; } return 0; } All of my programs use that idiom. (Also note: Error is not being caught; just Exception.) That try-catch block covers all Exception types that may be thrown. The user gets a useful message and we are done. Except, in some cases a specific exception type is useful. For example, I needed to catch ConvException that I know std.conv may throw. (This is documented on std.conv documentation.) In that case, I catch that exception in a lower-level function to give the user an understandable error message like "Failed to convert 'hello' to an integer" so that the user can try entering new data instead of exiting the whole program. Ali
Nov 15 2021
next sibling parent reply pascal111 <judas.the.messiah.111 gmail.com> writes:
On Monday, 15 November 2021 at 22:44:35 UTC, Ali Çehreli wrote:
 On 11/15/21 2:28 PM, pascal111 wrote:
 [...]
"throw" statement
 [...]
Such a list is not very useful. Normally all we need is Exception and occasionally one or two other specific types. [...]
What if I expect more than one exception a function can do in "try" block, and I need more than one "catch" block after that, so I'll need to define the exception, or you can turn around this with some way?
Nov 15 2021
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 11/15/21 3:00 PM, pascal111 wrote:
 On Monday, 15 November 2021 at 22:44:35 UTC, Ali =C3=87ehreli wrote:
 On 11/15/21 2:28 PM, pascal111 wrote:
 [...]
"throw" statement
 [...]
Such a list is not very useful. Normally all we need is Exception and=
 occasionally one or two other specific types.

 [...]
What if I expect more than one exception a function can do in "try" block,
One benefit of exceptions is separating actual work from error handling. = Code can be written as if everything will go well. If not, a higher=20 level function may catch the exception and e.g. start over. So, no=20 matter how many different kinds of exceptions may be thrown or no matter = how complicated a function is, we just do the work: void foo() { work(); moreWork(); etc(); } Some higher level function may have a try-catch, which may catch a=20 potential exception. Fine: // An intermediate function that uses foo: void zar() { foo(); } // A higher level function that uses the intermediate function: void bar() { // Try until successful while (true) { try { zar(); // It worked! Let's leave. return; } catch (Exception ex) { // Something bad happened // Let's try again... } } } bar() catches all exceptions without caring what exact type they are.=20 (In practice, for me, bar() is usually main(), the top level function.)
 and I need more than one "catch" block after that, so I'll need
 to define the exception, or you can turn around this with some way?
Well, if you *need* to handle a particular exception specially, then you = have to have a specific catch clause for that exception. Otherwise, a=20 single catch(Exception) is sufficient for most programs. That is possible because all exceptions inherit from Exception: class MyException : Exception { // ... } That definition means "MyException is an Exception", which allows=20 MyException objects to be caught as Exceptions as well. Exceptions are a useful tool but they are not suitable for all cases.=20 Maybe you have such a case. Ali
Nov 15 2021
prev sibling parent reply bauss <jj_1337 live.dk> writes:
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, because instead of writing your own custom exception then you could use an existing implementation.
Nov 16 2021
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 11/16/21 12:30 AM, bauss wrote:
 On Monday, 15 November 2021 at 22:44:35 UTC, Ali =C3=87ehreli 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=20 have been command line tools. I would love to learn more about how=20 others use exceptions. The existing exception type that I reuse is Exception :), which I throw=20 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=20 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 us=
e
 an existing implementation.
Unless there are standardized exceptions, that feels weird to me because = such reused exceptions may have constructor parameters which may not=20 make sense where I throw that exception. Luckily, there is basicExceptionCtors, which trivializes implementing=20 exception types anyway. For example, I copied the following from=20 /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=20 an existing exception of another module or a library. I don't know... That's my comfortable and lazy use of exceptions. :) Ali
Nov 16 2021
parent reply Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= <ola.fosheim.grostad gmail.com> writes:
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.
Nov 16 2021
parent Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= <ola.fosheim.grostad gmail.com> writes:
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?
Nov 16 2021