Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use exceptions not handled correctly within try block #1213

Closed
p6rt opened this issue Aug 8, 2009 · 5 comments
Closed

use exceptions not handled correctly within try block #1213

p6rt opened this issue Aug 8, 2009 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 8, 2009

Migrated from rt.perl.org#68318 (status was 'rejected')

Searchable as RT68318$

@p6rt
Copy link
Author

p6rt commented Aug 8, 2009

From ben@petering.net

# "Normal" exception in try {} is caught
BEGIN {
  try {
  widdle;
  CATCH {
  say "caught​: $!";
  }
  }
}

# But "use" is not.
BEGIN {
  try {
  use NonExistent; # dies, not caught.
  CATCH {
  say "caught​: $!";
  }
  }
}

Output (with Rakudo pulled 2009-08-08 06​:40 UTC, how on earth do you
specify revisions with git?)

  caught​: Could not find non-existent sub widdle
  Can't find ./NonExistent in @​*INC
  in Main (src\gen_setting.pm​:445)

(I'm not sure if this is correct, but I'm struggling to imagine why
this would be useful behavior.)

@p6rt
Copy link
Author

p6rt commented Aug 8, 2009

From ben@petering.net

In the second example, I'm not sure if that exception is a Control
exception... even if so, the problem still exists, because substituting
CONTROL for CATCH in that example results in the same output.

@p6rt
Copy link
Author

p6rt commented Aug 8, 2009

ben@petering.net - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 8, 2009

From @moritz

On Sat Aug 08 00​:00​:00 2009, missingthepoint wrote​:

# But "use" is not.
BEGIN {
try {
use NonExistent; # dies, not caught.
CATCH {
say "caught​: $!";
}
}
}

Output (with Rakudo pulled 2009-08-08 06​:40 UTC, how on earth do you
specify revisions with git?)

$ git-rev-parse HEAD
c13df6b482fefa9bd6f70572978ce0b32ede6b32

that's the revision (or simpler​: git-show | head )

 caught​: Could not find non\-existent sub widdle
 Can't find \./NonExistent in @​\*INC
 in Main \(src\\gen\_setting\.pm​:445\)

(I'm not sure if this is correct, but I'm struggling to imagine why
this would be useful behavior.)

'use' is executed at compile time, and try { } only catches run time
exceptions. You'd be very much surprised to get no parse errors from
within a try { } block, would you?

At the time of 'use' the try block isn't even parsed yet.

Perl 5 does the same, btw​:

$ perl -we 'eval { use Nonexisting }'
Can't locate Nonexisting.pm in @​INC (@​INC contains​:
/home/moritz/cpan/lib /etc/perl /usr/local/lib/perl/5.10.0
/usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5
/usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at
-e line 1.
BEGIN failed--compilation aborted at -e line 1.

So I reject this report as "not a bug".

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Aug 8, 2009

@moritz - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Aug 8, 2009
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant