Skip Menu |

This queue is for tickets about the Syntax-Feature-Try CPAN distribution.

Report information
The Basics
Id: 102808
Status: rejected
Priority: 0/
Queue: Syntax-Feature-Try

People
Owner: Nobody in particular
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Support try without catch
It would be useful to support a try {} block with no catch {} or finally {} block, for cases when you want to run some code ignoring all exceptions. (This is rare but sometimes useful.) Although I agree that doing so is questionable, and you can just have an empty catch {} block if wanted, other modules such as TryCatch support having try {} with no catch {}, so it would be a useful compatibility enhancement.
I think it is not necessary, you may use eval { ... }; for that case.
I agree that if starting from first principles a plain 'try' block would not be needed because you can 'eval'. But there are many try/catch implementations on CPAN and some of them do allow a plain 'try' block. Allowing it here too increases the portability of code between different try/catch implementations, which is a good thing. I think it does also make code a bit more consistent to use 'try' everywhere rather than have to change between 'try' and 'eval' according to whether a 'catch' block exists - in other words 'try' is more general if it allows zero or more 'catch' blocks, rather than one or more.
This try/catch module implements syntax similar to java or python. i.e. unlike "eval" any exception that are not caught by "catch block" is rethrown. This module is (maybe) not consistent with other "try/catch" implementations in CPAN, but it is consistent with principe: "Rethrow all unhandled exceptions". If I implement try{ } without catch block, than it rethrows any unhandled exceptions, so it would be same as "do { ... }", but I think it is not needed wrap this by "try block" if "all exception may be rethrown" (i.e. none catch blocks --> none exceptions are caught). So I think "try{}" block without catch{} or finally{} is useless in this case. Implementing "try {}" as "eval {}" would be inconsistent with other try {} catch {} blocks defined by this module, because: - "try {} catch {} blocks" says "Rethrow all unhandled exceptions" - "try {} finally {} blocks" says "Rethrow all unhandled exceptions" - but "try {}" block would say "Ignore all unhandled exceptions"?
OK, that makes sense. In fact it is better *not* to add support for try without catch, because it would end up with different semantics to what other CPAN modules have chosen.