try in shell

Tony Rogvall <[email protected]>
Newsgroups gmane.comp.lang.erlang.bugs
Message-ID <[email protected]>
Hi!

Not sure how this is supposed to be, given that there is a shell function called catch_exception/1.

Running in 17.1 (approx)

> try throw(x) catch Class:Reason -> {Class,Reason} end.
{throw,x}

> try exit(2) catch Class:Reason -> {Class,Reason} end.          
* exception exit: 2

> try foo:bar() catch Class:Reason -> {Class,Reason} end.        
* exception error: undefined function erl_eval:expr/3

> try 1/0 catch Class:Reason -> {Class,Reason} end.       
* exception error: an error occurred when evaluating an arithmetic expression

> try (a=b) catch Class:Reason -> {Class,Reason} end.
* exception error: no match of right hand side value b

Putting the above try expression in a module:

-module(tryme).
-compile(export_all).

test1() ->
    try throw(x) catch Class:Reason -> {Class,Reason} end.

test2() ->
    try exit(2) catch Class:Reason -> {Class,Reason} end.

test3() ->
    try (a=b) catch Class:Reason -> {Class,Reason} end.

test4() ->
    try 1/0 catch Class:Reason -> {Class,Reason} end.

test5() ->
    try foo:bar() catch Class:Reason -> {Class,Reason} end.


First compile:
tryme.erl:11: Warning: no clause will ever match
tryme.erl:14: Warning: this expression will fail with a 'badarith' exception

On line 11 there are no try clauses, but catch clauses that will always match, so the warning is a bit strange.
And the expression on line 14 is a try, so it will never fail with badarith, possibly return an error tuple lets see:

> tryme:test1().
{throw,x}
> tryme:test2().
{exit,2}
> tryme:test3().
{error,{badmatch,b}}
> tryme:test4().
{error,badarith}
> tryme:test5().
{error,undef}

This looks a bit more like I would expect.

Comments?

/Tony





_______________________________________________
erlang-bugs mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-bugs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.