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

  • Home
  • SEARCH
  • 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 824127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:03:15+00:00 2026-05-15T03:03:15+00:00

Throwing an exception via croak in a forked child process seems to print the

  • 0

Throwing an exception via croak in a forked child process seems to print the error as a background process would. That is, it clobbers the shell prompt.

If I die instead of croak, the the error message pops up as a foreground process. I’ve trying to find out why that is in the Carp documentation without any luck.

Here’s what I mean. The croak version:

$ perl Wrapper.pm
$ error: ... does not exist at Wrapper.pm line 624

The die version:

$ perl Wrapper.pm
error: ... does not exist at Wrapper.pm line 515.

I tried trapping the fork and printing $@ to STDERR and exiting, but that didn’t have an effect. Any ideas? I’d like to be able to use croak in this particular case.

Although my code is quite a bit more convoluted, here is how you can reproduce this behavior:

$ perl -MCarp -e 'unless (fork) {croak "child"}'
$ child at -e line 1
  <- cursor blinking here. Pressing enter gives me a new prompt:
$

$ perl -e 'unless (fork) {die "child"}'
child at -e line 1.
$

Solved: cjm got it:

$ perl -e '$SIG{__DIE__} = sub {sleep 1}; unless (fork) {die "child"}'
$ child at -e line 1.

Thanks for the help!

  • 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-05-15T03:03:16+00:00Added an answer on May 15, 2026 at 3:03 am

    I’m pretty sure it’s just a timing issue. The die version is slightly faster, so it has a better chance of outputting the error message before the shell can print the next prompt. When I try running your examples, the croak version usually gets printed after the prompt, but occasionally it comes before the prompt. The die version pretty consistently comes before the prompt.

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

Sidebar

Related Questions

How can I Handler 404 errors without the framework throwing an Exception 500 error
I have a third-party library that is sometimes throwing an exception. So I decided
I'm trying to test that I'm throwing an exception when appropriate. In my test
I try Request.Form.Set(k, v) but it's throwing exception Collection is read-only
What factors dictate throwing an exception if argument is null (eg if (a is
I am having trouble with XMLTextWriter.WriteStartElement throwing an exception: System.InvalidOperationException when trying to write
An older application using System.Web.Mail is throwing an exception on emails coming from hr@domain.com
Accidentally I may forget to describe some parameters or exception throwing (or something else)
I'm performing some parameter validation in a method and throwing an exception where necessary.
Also, how does it compare to throwing an exception when something goes wrong ?

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.