digitalmars.D - What is throwable
- Steve Teale (29/29) Mar 19 2009 The language reference says:
- Daniel Keep (3/6) Mar 19 2009 What class Throwable?
- Steve Teale (2/12) Mar 19 2009
- Daniel Keep (6/18) Mar 19 2009 Ah.
- Steve Teale (2/25) Mar 19 2009 But doesn't it rather imply that if you want to be able to throw a class...
- Jesse Phillips (3/32) Mar 19 2009 No, it just means that a Throwable object will provide a specific set of...
- Andrei Alexandrescu (20/43) Mar 19 2009 Yes, a check should be added to that effect. Later on we need to
- Ary Borenszweig (10/56) Mar 19 2009 You can't throw multiple exceptions in Java. What you can do is:
- Andrei Alexandrescu (3/66) Mar 19 2009 For allowing destructors to throw.
- Denis Koroskin (2/64) Mar 19 2009 Are you sure this is sound?
- Andrei Alexandrescu (4/18) Mar 19 2009 Yes. The notion that throwing destructors should terminate the
- Don (4/24) Mar 19 2009 And it causes lots of problems, in my experience. Since it usually
- Sean Kelly (7/31) Mar 19 2009 I've considered letting the user supply a custom "unhandled
- Sergey Gromov (5/37) Mar 19 2009 The problem is when you have a worker thread which never terminates and
- Sean Kelly (13/25) Mar 19 2009 So wrap your logic in a try/catch:
- Sean Kelly (6/8) Mar 19 2009 I think a case could be made for allowing only children of Throwable to
- Steve Teale (3/12) Mar 19 2009 It's exactly what you would expect based on the languages that D has bor...
The language reference says: Throw Statement Throw an exception. ThrowStatement: throw Expression ; Expression is evaluated and must be an Object reference. The Object reference is thrown as an exception. But the following compiles and runs and catches the RottenEgg. import std.stdio; class RottenEgg { string message; this(string s) { message = s; } } void main() { try { throw new RottenEgg("something smelly"); } catch (Exception e) { writefln("Caught exception ", e.toString()); } catch (RottenEgg err) { writefln("Caught RottenEgg exception ", err.message); } } What is the point of class Throwable if you can throw any old class object?
Mar 19 2009
Steve Teale wrote:... What is the point of class Throwable if you can throw any old class object?What class Throwable? -- Daniel
Mar 19 2009
Daniel Keep Wrote:Steve Teale wrote:dmd\src\druntime\src\compiler\dmd\object_.d... What is the point of class Throwable if you can throw any old class object?What class Throwable?-- Daniel
Mar 19 2009
Steve Teale wrote:Daniel Keep Wrote:Ah. Well, if I had to guess, I'd say it was because Throwable objects are more useful than random objects of other types. Object doesn't give you msg, file, line, info or next. -- DanielSteve Teale wrote:dmd\src\druntime\src\compiler\dmd\object_.d... What is the point of class Throwable if you can throw any old class object?What class Throwable?-- Daniel
Mar 19 2009
Daniel Keep Wrote:Steve Teale wrote:But doesn't it rather imply that if you want to be able to throw a class, then it should be derived from Throwable?Daniel Keep Wrote:Ah. Well, if I had to guess, I'd say it was because Throwable objects are more useful than random objects of other types. Object doesn't give you msg, file, line, info or next. -- DanielSteve Teale wrote:dmd\src\druntime\src\compiler\dmd\object_.d... What is the point of class Throwable if you can throw any old class object?What class Throwable?-- Daniel
Mar 19 2009
On Thu, 19 Mar 2009 06:09:40 -0400, Steve Teale wrote:Daniel Keep Wrote:No, it just means that a Throwable object will provide a specific set of information.Steve Teale wrote:But doesn't it rather imply that if you want to be able to throw a class, then it should be derived from Throwable?Daniel Keep Wrote:Ah. Well, if I had to guess, I'd say it was because Throwable objects are more useful than random objects of other types. Object doesn't give you msg, file, line, info or next. -- DanielSteve Teale wrote:dmd\src\druntime\src\compiler\dmd\object_.d... What is the point of class Throwable if you can throw any old class object?What class Throwable?-- Daniel
Mar 19 2009
Steve Teale wrote:Daniel Keep Wrote:Yes, a check should be added to that effect. Later on we need to actually exploit that only certain types can be thrown in implementing exception chaining. What is exception chaining? Consider: void weird() { scope(failure) throw new Exception1("hum"); throw new Exception2("ho"); } The C++ model terminates the app when an exception is thrown while the stack is unwound. Java (I was told without having checked) makes the latest exception thrown the "main" exception, and you get to also access the other exceptions by using primitives in class Exception. Is that true? Anyhow, we should implement a model in D that allows such multiple throws. Then a few primitives defined in class Exception - e.g. next() - should make the entire chain accessible. At some point Walter started implementing that but other priorities took over. A great side project for anyone if you ask me :o). AndreiSteve Teale wrote:But doesn't it rather imply that if you want to be able to throw a class, then it should be derived from Throwable?Daniel Keep Wrote:Ah. Well, if I had to guess, I'd say it was because Throwable objects are more useful than random objects of other types. Object doesn't give you msg, file, line, info or next. -- DanielSteve Teale wrote:dmd\src\druntime\src\compiler\dmd\object_.d... What is the point of class Throwable if you can throw any old class object?What class Throwable?-- Daniel
Mar 19 2009
Andrei Alexandrescu wrote:Steve Teale wrote:You can't throw multiple exceptions in Java. What you can do is: try { ... } catch(SomeException e) { throw new AnotherException(e); } and then AnotherException is thrown with "e" being it's inner exception, and you can check that.Daniel Keep Wrote:Yes, a check should be added to that effect. Later on we need to actually exploit that only certain types can be thrown in implementing exception chaining. What is exception chaining? Consider: void weird() { scope(failure) throw new Exception1("hum"); throw new Exception2("ho"); } The C++ model terminates the app when an exception is thrown while the stack is unwound. Java (I was told without having checked) makes the latest exception thrown the "main" exception, and you get to also access the other exceptions by using primitives in class Exception. Is that true?Steve Teale wrote:But doesn't it rather imply that if you want to be able to throw a class, then it should be derived from Throwable?Daniel Keep Wrote:Ah. Well, if I had to guess, I'd say it was because Throwable objects are more useful than random objects of other types. Object doesn't give you msg, file, line, info or next. -- DanielSteve Teale wrote:dmd\src\druntime\src\compiler\dmd\object_.d... What is the point of class Throwable if you can throw any old class object?What class Throwable?-- DanielAnyhow, we should implement a model in D that allows such multiple throws.What for?
Mar 19 2009
Ary Borenszweig wrote:Andrei Alexandrescu wrote:For allowing destructors to throw. AndreiSteve Teale wrote:You can't throw multiple exceptions in Java. What you can do is: try { ... } catch(SomeException e) { throw new AnotherException(e); } and then AnotherException is thrown with "e" being it's inner exception, and you can check that.Daniel Keep Wrote:Yes, a check should be added to that effect. Later on we need to actually exploit that only certain types can be thrown in implementing exception chaining. What is exception chaining? Consider: void weird() { scope(failure) throw new Exception1("hum"); throw new Exception2("ho"); } The C++ model terminates the app when an exception is thrown while the stack is unwound. Java (I was told without having checked) makes the latest exception thrown the "main" exception, and you get to also access the other exceptions by using primitives in class Exception. Is that true?Steve Teale wrote:But doesn't it rather imply that if you want to be able to throw a class, then it should be derived from Throwable?Daniel Keep Wrote:Ah. Well, if I had to guess, I'd say it was because Throwable objects are more useful than random objects of other types. Object doesn't give you msg, file, line, info or next. -- DanielSteve Teale wrote:dmd\src\druntime\src\compiler\dmd\object_.d... What is the point of class Throwable if you can throw any old class object?What class Throwable?-- DanielAnyhow, we should implement a model in D that allows such multiple throws.What for?
Mar 19 2009
On Thu, 19 Mar 2009 19:39:52 +0300, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Ary Borenszweig wrote:Are you sure this is sound?Andrei Alexandrescu wrote:For allowing destructors to throw. AndreiSteve Teale wrote:You can't throw multiple exceptions in Java. What you can do is: try { ... } catch(SomeException e) { throw new AnotherException(e); } and then AnotherException is thrown with "e" being it's inner exception, and you can check that.Daniel Keep Wrote:Yes, a check should be added to that effect. Later on we need to actually exploit that only certain types can be thrown in implementing exception chaining. What is exception chaining? Consider: void weird() { scope(failure) throw new Exception1("hum"); throw new Exception2("ho"); } The C++ model terminates the app when an exception is thrown while the stack is unwound. Java (I was told without having checked) makes the latest exception thrown the "main" exception, and you get to also access the other exceptions by using primitives in class Exception. Is that true?Steve Teale wrote:But doesn't it rather imply that if you want to be able to throw a class, then it should be derived from Throwable?Daniel Keep Wrote:Ah. Well, if I had to guess, I'd say it was because Throwable objects are more useful than random objects of other types. Object doesn't give you msg, file, line, info or next. -- DanielSteve Teale wrote:dmd\src\druntime\src\compiler\dmd\object_.d... What is the point of class Throwable if you can throw any old class object?What class Throwable?-- DanielAnyhow, we should implement a model in D that allows such multiple throws.What for?
Mar 19 2009
Denis Koroskin wrote:On Thu, 19 Mar 2009 19:39:52 +0300, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Yes. The notion that throwing destructors should terminate the application pronto is a prejudice we got from C++. AndreiAry Borenszweig wrote:Are you sure this is sound?Andrei Alexandrescu wrote:For allowing destructors to throw. AndreiAnyhow, we should implement a model in D that allows such multiple throws.What for?
Mar 19 2009
Andrei Alexandrescu wrote:Denis Koroskin wrote:And it causes lots of problems, in my experience. Since it usually doesn't terminate the app, just the thread with the defective destructor. Which is unnecessarily difficult to debug.On Thu, 19 Mar 2009 19:39:52 +0300, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Yes. The notion that throwing destructors should terminate the application pronto is a prejudice we got from C++. AndreiAry Borenszweig wrote:Are you sure this is sound?Andrei Alexandrescu wrote:For allowing destructors to throw. AndreiAnyhow, we should implement a model in D that allows such multiple throws.What for?
Mar 19 2009
== Quote from Don (nospam nospam.com)'s articleAndrei Alexandrescu wrote:I've considered letting the user supply a custom "unhandled exception" handler for threads. It just seemed messy given that calling join() on a thread now will rethrow the unhandled exception if there was one. I figured that the user would join threads he cared about, and if one he didn't care about terminated unexpectedly the perhaps that's not a problem.Denis Koroskin wrote:And it causes lots of problems, in my experience. Since it usually doesn't terminate the app, just the thread with the defective destructor. Which is unnecessarily difficult to debug.On Thu, 19 Mar 2009 19:39:52 +0300, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Yes. The notion that throwing destructors should terminate the application pronto is a prejudice we got from C++. AndreiAry Borenszweig wrote:Are you sure this is sound?Andrei Alexandrescu wrote:For allowing destructors to throw. AndreiAnyhow, we should implement a model in D that allows such multiple throws.What for?
Mar 19 2009
Thu, 19 Mar 2009 20:44:51 +0000 (UTC), Sean Kelly wrote:== Quote from Don (nospam nospam.com)'s articleThe problem is when you have a worker thread which never terminates and sends notifications to the main thread. Like game logic thread versus main GUI thread. If logic thread throws, your game suddenly stops working for no apparent reason.Andrei Alexandrescu wrote:I've considered letting the user supply a custom "unhandled exception" handler for threads. It just seemed messy given that calling join() on a thread now will rethrow the unhandled exception if there was one. I figured that the user would join threads he cared about, and if one he didn't care about terminated unexpectedly the perhaps that's not a problem.Denis Koroskin wrote:And it causes lots of problems, in my experience. Since it usually doesn't terminate the app, just the thread with the defective destructor. Which is unnecessarily difficult to debug.On Thu, 19 Mar 2009 19:39:52 +0300, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Yes. The notion that throwing destructors should terminate the application pronto is a prejudice we got from C++. AndreiAry Borenszweig wrote:Are you sure this is sound?Andrei Alexandrescu wrote:For allowing destructors to throw. AndreiAnyhow, we should implement a model in D that allows such multiple throws.What for?
Mar 19 2009
== Quote from Sergey Gromov (snake.scaly gmail.com)'s articleThu, 19 Mar 2009 20:44:51 +0000 (UTC), Sean Kelly wrote:So wrap your logic in a try/catch: void worker() { try { doStuff(); } catch( Throwable t ) { notifyProgramOfFailure( t ); } } auto t = new Thread( &worker ); I think a case could be made for simply terminating the app on an unhandled exception in a thread, but logic errors are the programmer's responsibility.I've considered letting the user supply a custom "unhandled exception" handler for threads. It just seemed messy given that calling join() on a thread now will rethrow the unhandled exception if there was one. I figured that the user would join threads he cared about, and if one he didn't care about terminated unexpectedly the perhaps that's not a problem.The problem is when you have a worker thread which never terminates and sends notifications to the main thread. Like game logic thread versus main GUI thread. If logic thread throws, your game suddenly stops working for no apparent reason.
Mar 19 2009
Steve Teale wrote:What is the point of class Throwable if you can throw any old class object?I think a case could be made for allowing only children of Throwable to be thrown. It's possible to throw integers and strings in C++, for example, which is totally ridiculous. However, at the moment Throwable simply serves as the common base class for Exception and Error, and holds file and line info as well as the stack trace hooks.
Mar 19 2009
Sean Kelly Wrote:Steve Teale wrote:It's exactly what you would expect based on the languages that D has borrowed from, but if it does not mean throwable, what's the point? I still don't know what the significance of Exception and Error might be.What is the point of class Throwable if you can throw any old class object?I think a case could be made for allowing only children of Throwable to be thrown. It's possible to throw integers and strings in C++, for example, which is totally ridiculous. However, at the moment Throwable simply serves as the common base class for Exception and Error, and holds file and line info as well as the stack trace hooks.
Mar 19 2009