Re: Particular exceptions names

2022-07-27 Thread kdevel via Digitalmars-d-learn
On Wednesday, 27 July 2022 at 09:35:12 UTC, Ali Çehreli wrote: The following program show an example as well as 'enforce', which I prefer over explicit if+throw+else: Me too. enforce!MissingArguments(args.length == 42, format!"Too few arguments: %s"(args.length)

Re: Particular exceptions names

2022-07-27 Thread kdevel via Digitalmars-d-learn
On Tuesday, 26 July 2022 at 23:43:59 UTC, pascal111 wrote: In next example code, it used user-made exception, [...] try { if( b == 0 ) { throw new Exception("Cannot divide by zero!"); } else { result = format("%s",a/b); } [..

Re: Particular exceptions names

2022-07-27 Thread pascal111 via Digitalmars-d-learn
On Wednesday, 27 July 2022 at 09:35:12 UTC, Ali Çehreli wrote: On 7/26/22 16:43, pascal111 wrote: > [...] I am not sure I understand you correctly because the program you show throws Exception, which is not user-made at all. [...] It seems an advanced topic. It'll take some more studying to

Re: Particular exceptions names

2022-07-27 Thread Ali Çehreli via Digitalmars-d-learn
On 7/26/22 16:43, pascal111 wrote: > In next example code, it used user-made exception, I am not sure I understand you correctly because the program you show throws Exception, which is not user-made at all. If you want to throw a particual exception that you define, you need to inherit that t

Re: Particular exceptions names

2022-07-27 Thread frame via Digitalmars-d-learn
On Tuesday, 26 July 2022 at 23:43:59 UTC, pascal111 wrote: In next example code, it used user-made exception, but what if I'm looking for a particular exception? from where can I get particular exception to arise it? There is no mechanism to find a particular exceptions in D. You have simple

Particular exceptions names

2022-07-26 Thread pascal111 via Digitalmars-d-learn
In next example code, it used user-made exception, but what if I'm looking for a particular exception? from where can I get particular exception to arise it? import std.stdio; import std.string; string division(int a, int b) { string result = ""; try { if(