July 30, 2010 [phobos] Calling abort() on unhandled exception | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Le 2010-07-30 ? 20:42, Andrei Alexandrescu a ?crit : > It's not that I want. It's an important use of the language. You could argue that D should not attempt to attempt scripting, but I think it should. That implies an ability to write short programs that do useful things. Scripting is an important use case, I do agree with that. What I disagree with is that not showing the stack trace does help in some way. I don't believe exceptions will give you pertinent enough messages most of the time. Except perhaps in some trivial 10-line demos you can show in your presentations. -- Michel Fortin michel.fortin at michelf.com http://michelf.com/ |
July 30, 2010 [phobos] Calling abort() on unhandled exception | ||||
---|---|---|---|---|
| ||||
Posted in reply to Leandro Lucarella |
Leandro Lucarella wrote:
>
> Andrei Alexandrescu, el 30 de julio a las 16:19 me escribiste:
>> David Simcha wrote:
>>> What's wrong with stack traces in short scripts? I use D all the time for short (< a few hundred lines) scripts and sometimes I use Python instead when I need a library that's not easily available in D or need to share my code with Python hackers. I honestly prefer Python's "always print a stack trace" to D's "make me fire up a debugger" for anything over ~50 lines (the point where I start to use functions instead of just writing all my code inline in main()).
>> I didn't know Python prints the stack trace on exception, so my previous argument just got destroyed :o).
>
> I said that in several mails before, but it looks like you choose to ignore them. Not only Python, most PL do that:
>
> Lua: http://codepad.org/l85PabyG
> PHP: http://codepad.org/aYsLHAZi
> Ruby: http://codepad.org/Wt3tPcvm
>
> I think Java and C# too (to count a few compiled languages), but
> I dont't have a compiler to test and codepad doesn't support them :)
Haven't seen that/those emails, sorry. Well, looks like I'm in the minority so I'll go with the flow.
Andrei
|
July 30, 2010 [phobos] Calling abort() on unhandled exception | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu, el 30 de julio a las 17:37 me escribiste: > Leandro Lucarella wrote: > >That's not an exception!!!! What's the point of that???? Why don't you > >just write a library function like like enforce but that uses exit(1) > >instead of throwing an exception for that?!?!?! You really want to > >sacrifice the correct behavior for this dumb, dumb "feature"??? > >This really makes me mad! God... > > Relax, we're all on the same boat. To answer each question in sequence: > > 1. The point of that is to terminate the program if the number of arguments passed is not satisfactory. > > 2. I don't write a library function like enforce that uses exit(1) because: > > 2.1. I'd have to write a ton of them. No, just one. The same way you don't have to write tons of enforece() functions, you don't have to write tons of die() functions. > 2.2. I don't want to exit(1), I want to correctly propagate an exception. In this particular case it would exit straight out of main so it's the same as exit(1) but many scripts have more than one function. No, you want to cleanly exit the program, the fact that C's exit() might not be appropriate doesn't mean that all exceptions should be treated as user errors. See bug 3462[1]. [1] http://d.puremagic.com/issues/show_bug.cgi?id=3462 > 3. I don't want to sacrifice correct behavior for anything in particular. It is your view that the behavior you like is correct and the one I like is incorrect. My view, and the view of most programming languages. And about abort() (this is mostly about stack traces now, but what I really think it's the most serious issue is not using abort()) you're still ignoring the fact that you can't get a debugger pointing to the place where the uncaught exception was originally thrown with your approach. You have multiple options to easily show errors to users, but not the other way around. I think that are very important arguments against your view. > >Plus *ANY* other programming language mark uncaught exceptions as > >OBVIOUS ERRORS (they print traces or abort()). > > Not Perl for example. I don't know whether Java prints the stack by default or not. Is funny that you use Perl as an example, because Perl doesn't have exceptions. See my other mail with examples of the multiple PL what actually support exceptions and how they print stack traces. -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- SATANAS EN COMISARIA -- Cr?nica TV |
July 30, 2010 [phobos] Calling abort() on unhandled exception | ||||
---|---|---|---|---|
| ||||
Posted in reply to Leandro Lucarella | Leandro Lucarella wrote: [snip] First rule of sales: after you closed the sale, immediately start talking about something else. Andrei |
July 30, 2010 [phobos] Calling abort() on unhandled exception | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | Michel Fortin, el 30 de julio a las 21:38 me escribiste: > Le 2010-07-30 ? 20:38, Andrei Alexandrescu a ?crit : > > > Leandro Lucarella wrote: > >> Calling abort() on Linux will simply print "Aborted". Do you think is that bad that worth being completely different than any other PL and making debug an uncaught exception almost imposible??? > > > > What is impossible about writing one try statement? > > If you have a debugger hooked, abort() will cause the debugger to stop the program in the state it currently is. If an uncaught exception doesn't unwind the stack and instead calls abort(), the debugger will stop the program exactly in the state the exception was thrown, not in a state where everything has been cleaned up and no clues as to what happened are left. > > It's like in the real world if you see a crime happen: don't clean up before calling the police, I guaranty the inspector won't appreciate. An uncaught exception is an error not expected by the programmer, it requires investigation to ensure the program's correctness. This investigation might not be worth it if it happens in a simple script, but to help debug a big program you shouldn't unwind the stack before calling abort(). Thanks, perfectly worded and excellent analogy. And that's what you can't do in a try statement, calling abort() (or do anything similar to "re-wind" the stack and go back to the past to the original place where the exception was thrown). -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- <o_O> parakenotengobarraespaciadora <o_O> aver <o_O> estoyarreglandolabarraporkeserompiounapatita |
Copyright © 1999-2021 by the D Language Foundation