Exception slipping through the catch block?

helxi brucewayneshit at gmail.com
Thu Nov 8 15:08:40 UTC 2018


How does exception work? I am inside a function that calls a 
constructor. Inside the constructor, an exception is thrown. 
However even though I have wrapped the body of the function 
inside a try/catch block, the program crashes from inside that 
constructor. Shouldn't the catch block in the function catch the 
exception?

Picture should clear it up a little bit:
https://i.imgur.com/3zinoZq.png

    // ui.d
    103	        deviceCombo.addOnChanged(delegate 
void(ComboBoxText _) {
    104	            try {
    105	                device = new 
Device(deviceCombo.getActiveText()); // <-- call sight
    106	                auto status = sanityCheck(device, 
fcb.getFilename);
    107	                if (status.pass)
    108	                    
triggerHboxRevealer.setRevealChild(true);
    109	                else {
    110	                    
deviceCombo.setTooltipText(status.reason);
    111	                    
triggerHboxRevealer.setRevealChild(false);
    112	                }
    113	            }
    114	            catch (Exception e) {
    115	                deviceCombo.setTooltipText("Cannot read 
device");
    116	                triggerHboxRevealer.setRevealChild(false);
    117	            }
    118	        });


     // backend.d
     34	    this(in string lsblkLine) {
     35	        auto lineSplit = lsblkLine.split(" ");
     36	        name = lineSplit.front();
     37	        sizePretty = lineSplit.back();
     38	        foreach (str; lineSplit.dropOne().dropBackOne()) 
// <-- throws exception
     39	            model ~= str ~ " ";
     40	        summary = format("%s\t%s\t%s", name, model, 
sizePretty);
     41	    }

// error message
core.exception.AssertError@/usr/include/dlang/dmd/std/range/primitives.d(2340): Assertion failure
----------------
??:? _d_assertp [0x4e81ee29]
/usr/include/dlang/dmd/std/range/primitives.d:2340 pure nothrow 
@nogc @safe void 
std.range.primitives.popBack!(immutable(char)[]).popBack(ref 
immutable(char)[][]) [0x4e5e417e]
/usr/include/dlang/dmd/std/range/package.d:3190 pure nothrow 
@nogc @safe immutable(char)[][] 
std.range.dropBackOne!(immutable(char)[][]).dropBackOne(immutable(char)[][]) [0x4e5e41d4]
source/backend.d:38 backend.Device 
backend.Device.__ctor(const(immutable(char)[])) [0x4e5e8e6d]
source/ui.d:105 void 
ui.PrimaryWindow.__ctor(gtk.Application.Application).__dgliteral4(gtk.ComboBoxText.ComboBoxText) [0x4e5ea17f]
../../../../.dub/packages/gtk-d-3.8.3/gtk-d/generated/gtkd/gobject/DClosure.d:135 extern (C) void gobject.DClosure.DClosure.d_closure_marshal!(void delegate(gtk.ComboBoxText.ComboBoxText)).d_closure_marshal(gobject.c.types.GClosure*, gobject.c.types.GValue*, uint, gobject.c.types.GValue*, void*, void*) [0x4e7bf095]
??:? g_closure_invoke [0x4f9573d4]
Program exited with code 1


More information about the Digitalmars-d-learn mailing list