Subclass TcpSocket?

bauss jacobbauss at gmail.com
Tue Mar 18 19:19:49 UTC 2025


On Tuesday, 18 March 2025 at 18:04:12 UTC, Steven Schveighoffer 
wrote:
> On Tuesday, 18 March 2025 at 07:42:37 UTC, Jonathan M Davis 
> wrote:
>> The base class constructors are not nothrow, so WrappedTCP's 
>> constructor cannot be nothrow. There really isn't a way out of 
>> that, because if a constructor throws, the object's state is 
>> destroyed. So, catching and handling the Exception to make 
>> your function nothrow isn't really an option like it would be 
>> with many functions.
>
> FWIW, this does compile:
>
> ```d
> class A
> {
>     this() {}
> }
>
> class B : A
> {
>     this() nothrow {
>         try {
>             super();
>         } catch(Exception e) {}
>     }
> }
> ```
> Not sure if it should...
>
> -Steve

Interesting that it doesn't break anything really.

```
import std;

class A
{
     this() { throw new Exception("test"); }
}

class B : A
{
     int a;

     this() nothrow {
         try {
             super();
         } catch(Exception e) {}
     }
}


void main()
{
     auto b = new B;
     b.a = 200;

     writeln(b.a);
}
```


More information about the Digitalmars-d-learn mailing list