26

Re: Error handling

Hello, Terix, you wrote: ARK>> Semanticheski this code - synchronous. That the compiler somewhere inside  it is simple a detail of implementation and no more. If I take other compiler which will create the synchronous code in this place does not change ANYTHING - neither the code, nor behavior of the program. T> is not present, it not so. The synchronous code  a flow and will do and wait, wait, wait for nothing and so the call something () then passes by next line yet does not end. Between something () and the next line other code does not put. And the asynchronous code returns control at once, other code any there, and that after a call something (), will be fulfilled separately then at once starts to be fulfilled. It is all I know. I speak about semantics of the code, instead of about details of specific implementation. The pancake, like all in  a post painted - all the same people do not understand. Here this code - "a = f () + 3;" - Synchronous or asynchronous? (Important specification for the people beaten to a context: it not C#.) Semanticheski - synchronous, that is looks and interacts with other code as synchronous. It is implemented as synchronous or asynchronous? Can be both so, and so. At current abstraction layer to us it .

27

Re: Error handling

ARK> It is all I know. I speak about semantics of the code, instead of about details of specific implementation. The pancake, like all in  a post painted - all the same people do not understand. In the previous post it is written that the behavior of the program will not change depending on what code generated the compiler - synchronous, or asynchronous. And it will change, because in case of the asynchronous code, something can put between something and the next line, and in case of the synchronous code - cannot.

28

Re: Error handling

Hello, Terix, you wrote: ARK>> It is all I know. I speak about semantics of the code, instead of about details of specific implementation. The pancake, like all in  a post painted - all the same people do not understand. T> in the previous post it is written that the behavior of the program will not change depending on what code generated the compiler - synchronous, or asynchronous. And it will change, because in case of the asynchronous code, something can put between something and the next line, and in case of the synchronous code - cannot. Yes, it agree, missed this moment. If to speak only about C#.

29

Re: Error handling

MTD> As consider has the right to life? Whether there are languages with such approach to error handling? Mandatory checks on the one hand - kindly, for the obvious reasons. On the other hand it is frequent they simply hinder and litter the code and waste time also nerves. Here more low already unsubscribed about it, but those are such variant not less. To return Option <int>. Option <int> plus (Option <int> x) {return x.map (el-> el + 2);} Accordingly function accepts one Option and returns another. Such operations it is possible to make much, but as a result at us will be any Option. At Option there is a method get which throws  if any of operations transited badly. try {print (x.get ()); catch (BadOptionException) {print ("a hogwash any");} If we try to perform operation on already beaten Option, it is led will not be, and to us silently return one more defective Option. Advantage here is that it is not necessary to suffer with  and that it is not necessary to check errors on everyone , and to check up only there where it is necessary. A lack that the primitive type should be turned and the code turns out unusual

30

Re: Error handling

Hello, Terix, you wrote: T> If we try to perform operation on already beaten Option, it is led will not be, and to us silently return one more defective Option. T> Advantage here is that it is not necessary to suffer with  and that it is not necessary to check errors on everyone , and to check up only there where it is necessary. The information on an error and a place/conditions of its appearance is lost.

31

Re: Error handling

Hello, night beast, you wrote: NB> Hello, Terix, you wrote: T>> If we try to perform operation on already beaten Option, it is led will not be, and to us silently return one more defective Option. T>> Advantage here is that it is not necessary to suffer with  and that it is not necessary to check errors on everyone , and to check up only there where it is necessary. NB> the information on an error and a place/conditions of its appearance is lost. Now in  languages, in that place where there will be an error, it will be generated . The method map catches it and saves for descendants. In  it will be written where, as as.  BadOptionException envelops this  and particulars can be received.

32

Re: Error handling

Hello, Terix, you wrote: T>>> If we try to perform operation on already beaten Option, it is led will not be, and to us silently return one more defective Option. T>>> Advantage here is that it is not necessary to suffer with  and that it is not necessary to check errors on everyone , and to check up only there where it is necessary. NB>> the information on an error and a place/conditions of its appearance is lost. T> now in  languages, in that place where there will be an error, it will be generated . The method map catches it and saves for descendants. In  it will be written where, as as.  BadOptionException envelops this  and particulars can be received. We admit. How problems are solved with violation of invariants of object at an exception?

33

Re: Error handling

Hello, night beast, you wrote: NB> Hello, Terix, you wrote: T>>>> If we try to perform operation on already beaten Option, it is led will not be, and to us silently return one more defective Option. T>>>> Advantage here is that it is not necessary to suffer with  and that it is not necessary to check errors on everyone , and to check up only there where it is necessary. NB>>> the information on an error and a place/conditions of its appearance is lost. T>> now in  languages, in that place where there will be an error, it will be generated . The method map catches it and saves for descendants. In  it will be written where, as as.  BadOptionException envelops this  and particulars can be received. NB> we admit. NB> as problems are solved with violation of invariants of object at an exception? Yes, perhaps, that in any way. It is necessary hands, as well as in cases with exceptions.

34

Re: Error handling

Hello, Terix, you wrote: NB>> it is admissible. NB>> as problems are solved with violation of invariants of object at an exception? T> yes, perhaps, that in any way. It is necessary hands, as well as in cases with exceptions. Well with exceptions at least clearly where , and at Optional to run into consequences it is possible in absolutely not not connected with it Optional a place.

35

Re: Error handling

NB> well with exceptions at least clearly where , and at Optional to run into consequences it is possible in absolutely not not connected with it Optional a place. You mean such case? Option <int> a = plus (a);//here error Option <string> b = getWeirdString (a);//Inside getWeirdString we do get at Option and we catch

36

Re: Error handling

Hello, Terix, you wrote: NB>> well with exceptions at least clearly where , and at Optional to run into consequences it is possible in absolutely not not connected with it Optional a place. You mean such case? T> T> Option <int> a = plus (a);//here error T> Option <string> b = getWeirdString (a);//Inside getWeirdString we do get at Option and we catch  are not present. Something like the such: Option <int> a = x.foo ();//here an error... x.bar ();//we try to work with curve x

37

Re: Error handling

Hello, night beast, you wrote: NB> Hello, Terix, you wrote: NB>>> well with exceptions at least clearly where , and at Optional to run into consequences it is possible in absolutely not not connected with it Optional a place. NB> you mean such case? T>> T>> Option <int> a = plus (a);//here error T>> Option <string> b = getWeirdString (a);//Inside getWeirdString we do get at Option and we catch  NB> NB> are not present. Something like the such: NB> NB> Option <int> a = x.foo ();//here error NB>... NB> x.bar ();//we try to work with curve x NB> It after all the same that int a =-1; try {a = x.foo ();} catch (Exception e) {Log. Info ("badly quitted, yes");// any with a quitted, but it not so excites us} x.bar ();//and to process a problem with curve  in the unit catch we forgot

38

Re: Error handling

Hello, Terix, you wrote: T> It after all the same that T> T> int a =-1; T> try {T> a = x.foo (); T>} catch (Exception e) {T> Log. Info ("badly quitted, yes");// any with a quitted, but it not so excites us T>} T> x.bar ();//and to process a problem with curve  in the unit catch we forgot T> yes, but with exceptions it is necessary to write it explicitly. Or Optional it is simple addition to exceptions? Then it is normal. For some reason solved that as the alternative is offered.

39

Re: Error handling

Hello, Terix, you wrote: CD>> I Congratulate! You invented a monad! CD>> Type Error Monad. CD>> Languages in which such is: CD>> CD>> Haskell CD>> F# CD>> OCaml CD>> Idris CD>> CD>> About first two is assured on 100 %, about remaining - it is less, as I do not work with them. CD>> For certain is also other languages with support of monads generally and monads of errors in particular. T> and in these monads there is an implicit conversion to , how in an idea in the first post? My God My God, well certainly is not present! You, should be,  - implicit conversions! Tell too...

40

Re: Error handling

CD> My God My God, well certainly is not present! You, should be,  - implicit conversions! Tell too... Well, means, monads not , and are refined

41

Re: Error handling

Hello, MTD, you wrote: MTD> During my labor activity I participated both in projects using exceptions, and in projects of errors using the codes. Now I am more declined to the second approach as exceptions really often become such implicit goto, besides their usage in the multi-threaded and asynchronous code becomes a pain. On the other hand, a failure from checks of return codes too it is bad. Let's up as it would be possible to organize ideal error handling. I while invented  both approaches through additional essence - well let there will be a performance flow (ExecutionFlow) which copy has each flow. The given essence implicitly is present at a call of each function, stores call stack and an error flag. To illustrate with the pseudocode easier: MTD> MTD> int plus2 ([it is implicit ExecutionFlow executionFlow], int x) MTD> {MTD> if (x <10) MTD> return RangeError ("bla-bla"); //the Output from function and error setting executionFlow.setError (RangeError ("bla-bla")) MTD> return x + 2;//Simply output and value reset, implicitly turns around in ReturnValue <int> MTD>} MTD> void foo () {...} MTD> MTD> the Causing code: MTD> MTD> var y = foo (5); MTD> if (y.success)//check, also installs in object ReturnValue <int> and ExecutionFlow a flag checked = true MTD> int z = bar (y);//implicitly it is led int if before coercion not to check up success the program writes a stack and it is completed MTD> if (! foo ().success) MTD> print (executionFlow.stackTrace ()); MTD> var error = executionFlow.error (); MTD> print (error.message ()) MTD> return error MTD> foo ();//did not check up success, the flag was not installed, means by a call of the following function (any) there will be a stack and abnormal termination MTD> MTD> As consider has the right to life? Whether there are languages with such approach to error handling? Has, of course, but  that forces the programmer to check errors in , and it would be necessary to fall down it on the compiler. Scala for example, There is type-wrapper Either <ErrorT, ResultT>. https://github.com/scala/scala/blob/2.1 … ther.scala the S-like pseudocode: Either <Error, Int> plus2 ([it is implicit ExecutionFlow executionFlow], int x) {if (x <10) return Left (RangeError ("bla-bla")); return Right (x + 2);} int z = plus2 (4).getOrElse {throw WtfException}//if happened any error, we throw an exception. Curly brackets are a lambda. int z = plus2 (4) match {//if RangeError, we throw an exception if other error - it is returned-1 case Right (result) => result case Left (RangeError (msg)) => throw WtfException ("Error:" + msg) case Left (otherError) =>-1} Either <Error, Int> result = plus2 (4) if (result.isLeft) {//the error} return result.get ()//throws an exception, if an error

42

Re: Error handling

Hello, Qbit86, you wrote: Q> the Mechanism of exceptions in language thus in any type can be (stack promotion), is simple they not intercepted (panic). It is possible examples of languages where the panic cannot be intercepted?

43

Re: Error handling

Hello, DarkEld3r, you wrote: Q>> the Mechanism of exceptions in language thus in any type can be (stack promotion), is simple they not intercepted (panic). DE> It is possible examples of languages where the panic cannot be intercepted? Rust.

44

Re: Error handling

Hello, Qbit86, you wrote: DE>> It is possible examples of languages where the panic cannot be intercepted? Q> Rust. Does not represent the facts: is std:: panic:: catch_unwind. Well and that two times not to rise: in Rust as there is a possibility to throw the caught panic and to check up type. That is, possibilities more or less correspond to exceptions unless to use it less conveniently, well and it "is not accepted".

45

Re: Error handling

Hello, DarkEld3r, you wrote: DE> is std:: panic:: catch_unwind. It is not recommended to use this function for a general try/catch mechanism. The ` Result ` type is more appropriate to use for functions that can fail on a regular basis. Additionally, this function is not guaranteed to catch all panics, see the "Notes" section below.

46

Re: Error handling

Hello, Qbit86, you wrote: Q> Hello, DarkEld3r, you wrote: DE>> is std:: panic:: catch_unwind. Q> It is not recommended to use this function for a general try/catch mechanism. The ` Result ` type is more appropriate to use for functions that can fail on a regular basis. Additionally, this function is not guaranteed to catch all panics, see the "Notes" section below. Well and I that wrote above? It is not recommended, yes. But it is possible to use. If confuses the remark, it generally about other. In pluses such, by the way, too is, only not in the standard, but popular compilers implement something of type-fno-exceptions. And if we write application, instead of library strategy of handling of a panic we can supervise. Anyway, Rust does not enter into the list of languages where it is impossible to intercept a panic. Whether also me is still interesting to eat such languages.

47

Re: Error handling

Hello, vsb, you wrote: MTD>> Here it also is the synchronous code, yes he pretends to be asynchronous, but its essence is that. vsb> All on the contrary. It is the asynchronous code which pretends to be synchronous. And it is again incorrect.) ) It is cooperative multitasking instead of forcing out. The resulted code synchronous, certainly, asynchronous in it is not present anything.>> In the present asynchronous code of such explicit synch points is not present Here still. And if I use cooperative multitasking library? For example, how in Windows 3.x by a call of any input-output operation? There absolutely same happened, only it was not necessary to specify explicitly await. I.e. all input-output was synchronous for a logical flow of execution, but asynchronous in computer "scale". vsb> after operation performance the output agent is caused is allows to load better the processor without wasting time on waiting. The processor also does not waste time on waiting. All wildness here it  const x = await something () has roots the high price of nuclear switchings of flows in MODERN  with the protected storage and anything more. If OS kernel switched flows with sufficient efficiency it would be possible to expect operation performance something sr-you the OS (through  asynchronous operation). But such code after all call synchronous, truly? vsb> it not synch point. These instructions of the code which will be fulfilled at result obtaining. It also is synch point of tasks directly on-definition.  Task is only the user-spejsnyj analog of process (flow) and anything more. vsb> Actually the point that if in language there are convenient means for operation with the asynchronous code Is not present. The resulted code - not asynchronous. It is beaten by nails to object Task, which in itself it is heavy enough. And necessity to declare environmental this  a method as async - so generally game and ha-ha 3 times.) ) For the comparing, any  the library of cooperative multitasking of it does not demand. , it is all  out of the blue. A crutch on  that cancer not to rise. vsb> (in JavaScript, Kotlin, like in C# too such is) exceptions perfectly approach for operation with errors. If such means are not present, with the asynchronous code to work very inconveniently anyway. In  and so it is inconvenient to work with the asynchronous code. For example, you cannot write the independent mechanism of cooperative dispatching and use it similarly sr-you of language. Well here are not pleasant to me heavy and stupid Task, I have superficial lock-free implementation Promise/Future which on orders is more convenient (because this approach is well worked in many languages). Here is how to me to use continuations from mine Future in similar syntax await, ?) ) Already in any way. Only explicitly to describe continuations on anonymous f-ijah that there is a game. But it will be that present asynchronous code, with all its "buns" (in the bad sense of this word).

48

Re: Error handling

Hello, Terix, you wrote: T> Is not present, it not so. The synchronous code  a flow and will do and wait, wait, wait for nothing In what you will express to "wait"? Something will happen, be consumed tics of the processor or what? T> and so the call something yet does not end () then passes by next line. In it  indeed. With that difference that dispatching  not at OS level, and at level the user-spejsnogo of the manager.

49

Re: Error handling

Hello, Terix, you wrote: T> In the previous post it is written that the behavior of the program will not change depending on what code generated the compiler - synchronous, or asynchronous. And it will change will not be. If on everyone  Task to create on a system flow and in a place of instructions of the operator await to expect synchronously operation completions the behavior will be completely identical. The difference will be only in efficiency. T> because in case of the asynchronous code, something can put between something and the next line, and in case of the synchronous code - cannot. In case of the synchronous other flow executing another Task can "put". As well as now, .

50

Re: Error handling

Hello, AlexRK, you wrote: ARK> Yes, it agree, missed this moment. If to speak only about C#. Be not conducted.)) you the people badly understanding an event in shown  powder a head.