Skip to content

Replace catch with try-catch to fix the compilation error in OTP-29 - #187

Open
jiahuili430 wants to merge 2 commits into
cmullaparthi:masterfrom
jiahuili430:replace-catch-to-try-catch
Open

jiahuili430 wants to merge 2 commits into
cmullaparthi:masterfrom
jiahuili430:replace-catch-to-try-catch

Conversation

@jiahuili430

@jiahuili430 jiahuili430 commented May 18, 2026 •

Copy link
Copy Markdown
Contributor
  • CI:

    • Add OTP-29 to GitHub Actions to run tests.
    • Update actions/checkout from v5 to v6.
  • Replace catch with try-catch to fix the compilation error in OTP-29:

$ make
...
src/ibrowse_lib.erl:65:10: 'catch ...' is deprecated; please use 'try ... catch ... end' instead.
Compile directive 'nowarn_deprecated_catch' can be used to suppress
warnings in selected modules.
%   65|     case catch decode_rfc822_date_1(string:tokens(String, ", \t\r\n")) of
%     |
...

- Add `OTP-29` to GitHub Actions to run tests.
- Update actions/checkout from `v5` to `v6`.
@jiahuili430
jiahuili430 force-pushed the replace-catch-to-try-catch branch from 07ad5f1 to ff5d372 Compare May 23, 2026 21:20
Comment thread src/ibrowse.erl Outdated
Comment on lines +1062 to +1064
throw:Term -> Term;
exit:Reason -> {'EXIT', Reason};
error:Reason:Stacktrace -> {'EXIT', {Reason, Stacktrace}}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw:Term -> Term;
exit:Reason -> {'EXIT', Reason};
error:Reason:Stacktrace -> {'EXIT', {Reason, Stacktrace}}
_:_ ->
ok

@jiahuili430 jiahuili430 May 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review!

Updated to use the ?TRY_CATCH() macro to slightly simplify the code.

catch can handle throw, but not exit or error. If modify them to _:_ -> ok,
the behavior of the function will be changed.

1> catch(ok).
ok
2> catch(throw(throw_error)).
throw_error
3> catch(exit(timeout)).
{'EXIT',timeout}
4> catch(exit({timeout, reason})).
{'EXIT',{timeout,reason}}
5> catch(error({noproc, reason})).
{'EXIT',{{noproc,reason},
         [{shell,apply_fun,3,[{file,"shell.erl"},{line,1209}]},
          {erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,1048}]},
          {erl_eval,expr,6,[{file,"erl_eval.erl"},{line,780}]},
          {shell,exprs,7,[{file,"shell.erl"},{line,970}]},
          {shell,eval_exprs,7,[{file,"shell.erl"},{line,926}]},
          {shell,eval_loop,4,[{file,"shell.erl"},{line,911}]}]}}

Also, documentation mentioned this, see https://www.erlang.org/doc/system/expressions.html#try

Next is an example of using try to emulate catch Expr:

try Expr
catch
  throw:Term -> Term;
  exit:Reason -> {'EXIT',Reason};
  error:Reason:Stk -> {'EXIT',{Reason,Stk}}
end

Fix the following compilation errors:

```bash
$ make
src/ibrowse_lib.erl:65:10: 'catch ...' is deprecated; please use 'try ... catch ... end' instead.
Compile directive 'nowarn_deprecated_catch' can be used to suppress
warnings in selected modules.
%   65|     case catch decode_rfc822_date_1(string:tokens(String, ", \t\r\n")) of
%     |
```
@jiahuili430
jiahuili430 force-pushed the replace-catch-to-try-catch branch from ff5d372 to 817fed6 Compare May 23, 2026 22:59
@jiahuili430
jiahuili430 requested a review from cmullaparthi May 23, 2026 23:00
nickva added a commit to nickva/ibrowse that referenced this pull request Jun 7, 2026
In OTP 29 catch statements started to throw deprecation warnings, and since
we're using `warnings_as_errors` our compilation fails. The catch construct
hasn't been scheduled for removal yet [1] so for now just to compile ibrowse
add a per-module compiler directive. This allows catch rewrites to be done
incrementally module-by-module eventually.

This is an intermediate alternative for
cmullaparthi#187 for now.

[1] https://www.erlang.org/doc/scheduled_for_removal.html
@nickva nickva mentioned this pull request Jun 7, 2026
@big-r81

big-r81 commented Jun 9, 2026

Copy link
Copy Markdown

@cmullaparthi This would be nice to get into the main branch in combination with #189 and #190 😃.

nickva added a commit to nickva/ibrowse that referenced this pull request Jun 13, 2026
In OTP 29 catch statements started to throw deprecation warnings, and since
we're using `warnings_as_errors` our compilation fails. The catch construct
hasn't been scheduled for removal yet [1] so for now just to compile ibrowse
add a per-module compiler directive. This allows catch rewrites to be done
incrementally module-by-module eventually.

This is an intermediate alternative for
cmullaparthi#187 for now.

[1] https://www.erlang.org/doc/scheduled_for_removal.html
nickva added a commit to apache/couchdb-ibrowse that referenced this pull request Jun 13, 2026
In OTP 29 catch statements started to throw deprecation warnings, and since
we're using `warnings_as_errors` our compilation fails. The catch construct
hasn't been scheduled for removal yet [1] so for now just to compile ibrowse
add a per-module compiler directive. This allows catch rewrites to be done
incrementally module-by-module eventually.

This is an intermediate alternative for
cmullaparthi/ibrowse#187 for now.

[1] https://www.erlang.org/doc/scheduled_for_removal.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants