Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:18:39+00:00 2026-06-10T15:18:39+00:00

consider the code bleow: -module(add_two). -compile(export_all). start()-> process_flag(trap_exit, true), Pid = spawn_link(add_two, loop, []),

  • 0

consider the code bleow:

-module(add_two).
-compile(export_all).

start()->
    process_flag(trap_exit, true),
    Pid = spawn_link(add_two, loop, []),
    register(add_two, Pid),
    ok.

request()->
    add_two ! bad,
    receive
        {'EXIT', _Pid, Reason} -> io:format("self:~w~n", [{error, Reason}]);
        {Result}               -> io:format("result:~w~n", [Result])
    after
        1000->timeout
    end.

loop()->
    receive
        bad                 -> exit(nogoodreason_bad);
        {request, Pid, Msg} -> Pid ! {result, Msg + 2}
    end,
    loop().

when I test the code above in shell,I get two different results with different input order,but why?

first input order :

Eshell V5.9.1  (abort with ^G)
1> add_two:request(ddd).
** exception error: undefined function add_two:request/1
2> add_two:start().
ok
3> add_two:request(). 
self:{error,nogoodreason_bad}
ok

second input order:

Eshell V5.9.1  (abort with ^G)
1> add_two:start().
ok
2> add_two:request(ddd).
** exception error: undefined function add_two:request/1
3> add_two:request().
** exception error: bad argument
     in function  add_two:request/0 (add_two.erl, line 11)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:18:40+00:00Added an answer on June 10, 2026 at 3:18 pm

    The call add_two:request(ddd) makes the shell process die, taking add_two down with it, due to the spawn_link() call. You can confirm this by checking the shell’s pid before and after an exception. It doesn’t even have to involve the add_two module:

    12> self().
    <0.61.0>
    13> 2+2.
    4
    14> self().
    <0.61.0>
    15> 1/0.
    ** exception error: bad argument in an arithmetic expression
         in operator  '/'/2
            called as 1 / 0
    16> self().
    <0.69.0>
    17> 
    

    You can avoid this effect either by calling spawn instead of spawn_link, or trapping and handling exits in the spawned process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the code below: -module(except). -compile(export_all). divone(X)-> erlang:error({badnews,erlang:get_stacktrace()}),1/X-1. tryreturn(X)-> try divone(X) of Val->{result,2/Val} catch
Consider this code: if(initscr() == NULL) ERROR(Cannot start ncurses mode.\n); keypad(stdscr, TRUE); cbreak(); int
I have a code snippet as below <CheckBox Name=cb Margin=1,2,1,0 IsChecked={Binding Path=IsManager} IsEnabled=True/> Consider
Please, consider the code below: template<typename T> bool function1(T some_var) { return true; }
Consider the code below, private void Convert_Click(Object sender, RoutedEventArgs e) { string[] strCmdLineParams =
Consider the code below. I don't understand why my GCC compiler does not try
Consider the JavaScript code below, inspired from the YUI documentation on YAHOO.lang.extend . In
Consider the Java code below, what would happen if there were no paintComponent method
I am having trouble finding an answer to this. Consider the clipping code below:
Consider this code: enum { ERR_START, ERR_CANNOTOPENFILE, ERR_CANNOTCONNECT, ERR_CANNOTCONNECTWITH, ERR_CANNOTGETHOSTNAME, ERR_CANNOTSEND, }; char* ERR_MESSAGE[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.