Comments (6)
I disagree. We wanted to always use try in the book to show people the
more correct way of doing things. That said, catch is not deprecated,
and in my opinion is nicer in some instances because it makes for
fewer lines of code. Unless and until they depricate catch I think it
is quite valid.
On Fri, Apr 22, 2011 at 9:24 AM, ericbmerritt
[email protected]
wrote:
It should use try catch, and probably should be moved to a ec_int
module or something along those lines. At the very least it should be
moved to try catch.Reply to this email directly or view it on GitHub:
#6
Martin Logan
Erlang & OTP in Action (Manning) http://manning.com/logan
http://twitter.com/martinjlogan
http://erlware.org
from erlware_commons.
its not depricated (though in my opinion it should be) its just heavily discouraged by the implementors. The reason its heavily discouraged and for very good reason. Its not selective, you catch everything regardless of whether you want to catch it or not, regardless of whether you can deal with it or not. Sometimes thats ok, sometimes its not, but you almost never know when its ok and when its no. So its best just not to use it, especially when there is a good construct that does the exact some thing in a more reasonable way. Its worth 3 (yes 3) additional lines of code to get rid of the ambiguity.
from erlware_commons.
That is the advantage of it. You often times do want to catch
everything, particularly in a dynamic language where exceptions thrown
are sparsely documented. Ideally it would be great to know exactly
what will come back and deal with each case accordingly. If you survey
the use of try though you will see many instances of
try
...
catch
_C:_E ->
...
end
Using catch in this case is more succinct.
On Sat, Apr 23, 2011 at 5:40 PM, ericbmerritt
[email protected]
wrote:
its not depricated (though in my opinion it should be) its just heavily discouraged by the implementors. The reason its heavily discouraged and for very good reason. Its not selective, you catch everything regardless of whether you want to catch it or not, regardless of whether you can deal with it or not. Sometimes thats ok, sometimes its not, but you almost never know when its ok and when its no. So its best just not to use it, especially when there is a good construct that does the exact some thing in a more reasonable way. Its worth 3 (yes 3) additional lines of code to get rid of the ambiguity.
Reply to this email directly or view it on GitHub:
#6 (comment)
Martin Logan
Erlang & OTP in Action (Manning) http://manning.com/logan
http://twitter.com/martinjlogan
http://erlware.org
from erlware_commons.
I can't think of a single case where you want to catch everything. It may appear that you want to catch everything, but you don't actually. Take the simple case of your to_int, what you really want to capture there is conversion errors. Do you want to also catch out of memory errors? do you want to catch possible exits (you have no clue what could be thrown under the covers after all), or any number of other things that could happen? no in the vast majority of cases no, you don't. Not only that but if you catch those errors it can cause unexpected behaviour in your system.
You have just done a great job of illustrating exactly why catch should be avoided in nearly every case. It does what you think you want it to do, not actually what you want it to do.
from erlware_commons.
As we spoke about on the phone we will agree to disagree on this.
On Tue, Apr 26, 2011 at 8:34 AM, ericbmerritt
[email protected]
wrote:
I can't think of a single case where you want to catch everything. It may appear that you want to catch everything, but you don't actually. Take the simple case of your to_int, what you really want to capture there is conversion errors. Do you want to also catch out of memory errors? do you want to catch possible exits (you have no clue what could be thrown under the covers after all), or any number of other things that could happen? no in the vast majority of cases no, you don't. Not only that but if you catch those errors it can cause unexpected behaviour in your system.
You have just done a great job of illustrating exactly why catch should be avoided in nearly every case. It does what you think you want it to do, not actually what you want it to do.
Reply to this email directly or view it on GitHub:
#6 (comment)
Martin Logan
Erlang & OTP in Action (Manning) http://manning.com/logan
http://twitter.com/martinjlogan
http://erlware.org
from erlware_commons.
ec_semver has been massively refactored. in the process, this issue no longer applies
from erlware_commons.
Related Issues (20)
- Problems using erlware_commons as dependency HOT 8
- Does not compile with newest rebar3 HOT 1
- Incorrect ISO 8601 formatting
- Hex.pm versioning does not seem to match tags
- build ec_plists.erl failed HOT 1
- Discrepancy between hex.pm vs. the COPYING file HOT 2
- please tag next version (0.23.0 ?) HOT 14
- ec_date:parse not parsing microseconds when timezone offset is given
- Git tag 1.0.5 missing? HOT 1
- ec_file:copy fails for not owned source file with OTP 21-rc2 HOT 9
- runmany_wrap doesn't actually call the passed function
- ec_semver:parse() incorrectly parsing "pre-release identifier" containing hyphen HOT 6
- Warnings emitted on OTP 24 prevent Rebar 3 bootstrap HOT 1
- Badarg error while performing rebar cover HOT 1
- A new tag is needed by erlang/otp 24.0-rc1
- Request for Hex.pm publication HOT 5
- ec_cmd_log doesn't support unicode chars
- ec_date:format() incorrectly formating 'G' in the format parameter string
- The pattern <State, Color, 'true', Msg> can never match the type <_,99 | 103 | 109 | 114,'false',_> HOT 2
- Unknown function compile:forms/2 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from erlware_commons.