Re: How to use exceptions

2022-08-13 Thread Christian Köstlin via Digitalmars-d-learn
On 13.08.22 17:00, kdevel wrote: "Exception enrichment" would be my wording which is supported by google [1]. There is also the notion of "exception context" [2] and "contexted exception" [3]. Thats really a good word! Especially it describes better what the java guys are doing by adding

Re: How to use exceptions

2022-08-13 Thread kdevel via Digitalmars-d-learn
On Saturday, 13 August 2022 at 13:36:08 UTC, Christian Köstlin wrote: [...] 1. error handling in main path: exactly thats what I would like todo. but for that the errors that raise need to have meaningful information. this is exactly what I am trying in those context* functions ... they do

Re: How to use exceptions

2022-08-13 Thread Christian Köstlin via Digitalmars-d-learn
On 13.08.22 15:00, kdevel wrote: On Friday, 12 August 2022 at 21:41:25 UTC, Christian Köstlin wrote: which would enable something like ```d     return  s     .readText     .parseJSON     .contextWithException((UTFException e) {     return new Exception("Cannot process

Re: How to use exceptions

2022-08-13 Thread kdevel via Digitalmars-d-learn
On Friday, 12 August 2022 at 21:41:25 UTC, Christian Köstlin wrote: which would enable something like ```d return s .readText .parseJSON .contextWithException((UTFException e) { return new Exception("Cannot process UTF-8 in config file%s\n

Re: How to use exceptions

2022-08-12 Thread Christian Köstlin via Digitalmars-d-learn
On 12.08.22 23:05, Christian Köstlin wrote: On 12.08.22 01:50, H. S. Teoh wrote: ... > The OP's idea of wrapping throwing code with a function that tacks on extra information is a good idea.  Perhaps the use of strings isn't ideal, but in principle I like his idea of exceptions acquiring

Re: How to use exceptions

2022-08-12 Thread Christian Köstlin via Digitalmars-d-learn
On 12.08.22 01:50, H. S. Teoh wrote: ... > The OP's idea of wrapping throwing code with a function that tacks on extra information is a good idea. Perhaps the use of strings isn't ideal, but in principle I like his idea of exceptions acquiring higher-level information as it propagates up the

Re: How to use exceptions

2022-08-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 12 August 2022 at 00:40:48 UTC, H. S. Teoh wrote: Hmm! That gets me thinking. Maybe something like this? aye. and scopes share dtors which means we can do it in the lib today: --- struct AdditionalInfo { static string[] info; this(string info) {

Re: How to use exceptions

2022-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 12, 2022 at 12:12:13AM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Thursday, 11 August 2022 at 23:50:58 UTC, H. S. Teoh wrote: > > I think the OP's idea is somewhat different: adding contextual > > information to a propagating exception that the throwing code may > > not

Re: How to use exceptions

2022-08-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 11 August 2022 at 23:50:58 UTC, H. S. Teoh wrote: I think the OP's idea is somewhat different: adding contextual information to a propagating exception that the throwing code may not have access to. Yeah, but you can use the mechanism again: you'd catch the one then throw a new

Re: How to use exceptions

2022-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 11, 2022 at 11:06:45PM +, Adam D Ruppe via Digitalmars-d-learn wrote: > You might find my recent blog post interesting too: > > http://dpldocs.info/this-week-in-d/Blog.Posted_2022_08_01.html#exception-template-concept > > and a draft of some more concepts: >

Re: How to use exceptions

2022-08-11 Thread Christian Köstlin via Digitalmars-d-learn
On 12.08.22 01:06, Adam D Ruppe wrote: You might find my recent blog post interesting too: http://dpldocs.info/this-week-in-d/Blog.Posted_2022_08_01.html#exception-template-concept and a draft of some more concepts: http://arsd-official.dpldocs.info/source/arsd.exception.d.html I also find

Re: How to use exceptions

2022-08-11 Thread Adam D Ruppe via Digitalmars-d-learn
You might find my recent blog post interesting too: http://dpldocs.info/this-week-in-d/Blog.Posted_2022_08_01.html#exception-template-concept and a draft of some more concepts: http://arsd-official.dpldocs.info/source/arsd.exception.d.html I also find the lack of information disturbing, but I

How to use exceptions

2022-08-11 Thread Christian Köstlin via Digitalmars-d-learn
Dear d-lang experts, lets say in general I am quite happy with exceptions. Recently though I stumbled upon two problems with them: 1. Its quite simple to loose valuable information 2. Its hard to present the exception messages to end users of your program Let me elaborate on those: Lets take