digitalmars.D.learn - Exception Handling, Scope and Destructor questions
- orgoton (23/23) Feb 12 2007 The D specification says that when an object is destroyer (either implic...
- Kirk McDonald (10/38) Feb 12 2007 No. The first matching catch block is the one that is used. The last one...
- Jarrett Billingsley (5/8) Feb 12 2007 Wow, you learn something new every day :) Never knew you could make
- Kirk McDonald (8/20) Feb 12 2007 C++'s treatment of this topic is one of its many freakish features:
- Deewiant (7/13) Feb 13 2007 Incorrect. try doesn't need it, but catch does, and I would expect final...
- Jarrett Billingsley (9/16) Feb 13 2007 This works:
The D specification says that when an object is destroyer (either implicitly or by GC action) the destructors of al inherited classes are also called. However, if I have a class "one" and a class "two", which inherits from class "one", if I call any instance of "two", the destructor of "one" also gets called. The question is: if I use a reference to "two" in form of "one", will the destructor of "two" be called? ONE handle=new TWO; delete handle; Next question: I have a try block which may have one of several exceptions thrown, and depending on which, I call a different catch: try { something();} catch(ExceptionType1 e) { process(); } catch(ExceptionType2 e) { process 2; } catch(Exception e) { ProcessGeneric(); } Since ExceptionType1 and Type2 both inherit from call Exception, does the last catch execute along with Type1 or Type2? Please confirm, the finally{} block ALWAYS gets called, right? Lastly, the catch() does not need to have a scope, yes? something like catch(Exception e) ProcessGeneric(); in summary of the code above?
Feb 12 2007
orgoton wrote:The D specification says that when an object is destroyer (either implicitly or by GC action) the destructors of al inherited classes are also called. However, if I have a class "one" and a class "two", which inherits from class "one", if I call any instance of "two", the destructor of "one" also gets called. The question is: if I use a reference to "two" in form of "one", will the destructor of "two" be called? ONE handle=new TWO; delete handle;Yes. Destructors are virtual.Next question: I have a try block which may have one of several exceptions thrown, and depending on which, I call a different catch: try { something();} catch(ExceptionType1 e) { process(); } catch(ExceptionType2 e) { process 2; } catch(Exception e) { ProcessGeneric(); } Since ExceptionType1 and Type2 both inherit from call Exception, does the last catch execute along with Type1 or Type2?No. The first matching catch block is the one that is used. The last one is only executed when an exception other than Type1 or Type2 is thrown.Please confirm, the finally{} block ALWAYS gets called, right?Yes.Lastly, the catch() does not need to have a scope, yes? something like catch(Exception e) ProcessGeneric(); in summary of the code above?Yes, this is allowed. -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org
Feb 12 2007
"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:eqqjbc$ebp$1 digitalmars.com...Wow, you learn something new every day :) Never knew you could make try/catch/finally statements without the braces. Huh. I'll have to add that to MiniD.Lastly, the catch() does not need to have a scope, yes? something like catch(Exception e) ProcessGeneric(); in summary of the code above?Yes, this is allowed.
Feb 12 2007
Jarrett Billingsley wrote:"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:eqqjbc$ebp$1 digitalmars.com...C++'s treatment of this topic is one of its many freakish features: http://www.everything2.com/index.pl?node_id=1429017 -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.orgWow, you learn something new every day :) Never knew you could make try/catch/finally statements without the braces. Huh. I'll have to add that to MiniD.Lastly, the catch() does not need to have a scope, yes? something like catch(Exception e) ProcessGeneric(); in summary of the code above?Yes, this is allowed.
Feb 12 2007
Kirk McDonald wrote:orgoton wrote:Incorrect. try doesn't need it, but catch does, and I would expect finally to, as well. try foo(); catch bar(); // doesn't work try foo(); catch { bar(); } // fineLastly, the catch() does not need to have a scope, yes? something like catch(Exception e) ProcessGeneric(); in summary of the code above?Yes, this is allowed.
Feb 13 2007
"Deewiant" <deewiant.doesnotlike.spam gmail.com> wrote in message news:eqsvi1$8uv$1 digitalmars.com...Incorrect. try doesn't need it, but catch does, and I would expect finally to, as well. try foo(); catch bar(); // doesn't work try foo(); catch { bar(); } // fineThis works: try foo(); catch(Object o) // notice you have to put an exception name here bar(); finally baz();
Feb 13 2007