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 8541129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:45:37+00:00 2026-06-11T11:45:37+00:00

I am using Try::Tiny for try-catch. Code goes as below: use Try::Tiny; try {

  • 0

I am using Try::Tiny for try-catch.

Code goes as below:

use Try::Tiny;

try {
    print "In try";
    wrongsubroutine();  # undefined subroutine
}
catch {
    print "In catch";
}

somefunction();

…

sub somefunction {
    print "somefunction";
}

When I execute
It comes like this:

somefunction
In Try
In catch

The output sequence looks wrong to me. Is it wrong? or Is this normal behavior?

  • 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-11T11:45:38+00:00Added an answer on June 11, 2026 at 11:45 am

    Just like forgetting a semi-colon in

    print
    somefunction();
    

    causes the output somefunction to be passed to print instead of $_, a missing semi-colon is causing the output of somefunction to be passed as an argument to catch.

    try {
       ...
    }
    catch {
       ...
    };      <--------- missing
    somefunction();
    

    try and catch are subroutines with the &@ prototype. That means

    try { ... } LIST
    catch { ... } LIST
    

    is the same as

    &try(sub { ... }, LIST)
    &catch(sub { ... }, LIST)
    

    So your code is the same as

    &try(sub { ... }, &catch(sub { ... }, somefunction()));
    

    As you can see, the missing semi-colon after the catch block is causing somefunction to be called before catch (which returns an object that tells try what to do on exception) and try.

    The code should be

    &try(sub { ... }, &catch(sub { ... })); somefunction();
    

    which is achieved by placing a semi-colon after the try-catch call.

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

Sidebar

Related Questions

Out of habit I've been using try/catch blocks in my application code for all
I am writing a stored procedure where i m using try catch block. Now
How can I avoid NullPointerExceptions ? I have tried using try-catch blocks but that
Anyone knows why my sql query doesn't work after using a try catch function?
I know how to handle exceptions using Try .. catch kind what i actually
Possible Duplicate: Performance of try-catch in php While using try - catch blocks, even
What is a decent way to handle PDO error when using try catch block?
I have found how to validate that an input is a number using try/catch
With C++, I try to #define TINY std::pow(10,-10) I give the code with the
Instead of using try/catch blocks everytime I need to construct any objects after allocating

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.