Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
6f8ab567
Commit
6f8ab567
authored
20 years ago
by
Abel Ureta-Vidal
Browse files
Options
Downloads
Patches
Plain Diff
Import all method by default if none is specified. Added try/catch syntax
parent
7764b897
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/Bio/EnsEMBL/Utils/Exception.pm
+67
-7
67 additions, 7 deletions
modules/Bio/EnsEMBL/Utils/Exception.pm
with
67 additions
and
7 deletions
modules/Bio/EnsEMBL/Utils/Exception.pm
+
67
−
7
View file @
6f8ab567
...
@@ -8,16 +8,31 @@ Bio::EnsEMBL::Utils::Exception - Utility functions for error handling
...
@@ -8,16 +8,31 @@ Bio::EnsEMBL::Utils::Exception - Utility functions for error handling
=head1 SYNOPSIS
=head1 SYNOPSIS
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate verbose)
use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate verbose try catch);
or to get all methods just
use Bio::EnsEMBL::Utils::Exception;
eval {
eval {
throw("this is an exception with a stack trace");
throw("this is an exception with a stack trace");
)
;
}
;
if($@) {
if($@) {
print "Caught exception:\n$@";
print "Caught exception:\n$@";
}
}
# or you can us the try/catch confortable syntax instead
# to deal with throw or die.
# don't forget the ";" after the catch block
# With this syntax, the original $@ is in $_ in the catch subroutine.
try {
throw("this is an exception with a stack trace");
} catch {
print "Caught exception:\n$_";
};
#silence warnings
#silence warnings
verbose('OFF');
verbose('OFF');
...
@@ -74,12 +89,11 @@ package Bio::EnsEMBL::Utils::Exception;
...
@@ -74,12 +89,11 @@ package Bio::EnsEMBL::Utils::Exception;
use
Exporter
;
use
Exporter
;
use
vars
qw(@ISA @EXPORT
_OK
)
;
use
vars
qw(@ISA @EXPORT)
;
@ISA
=
qw(Exporter)
;
@ISA
=
qw(Exporter)
;
@EXPORT
=
qw(throw warning stack_trace_dump
@EXPORT_OK
=
qw(&throw &warning &stack_trace_dump
stack_trace verbose deprecate info try catch)
;
&stack_trace &verbose &deprecate &info)
;
my
$VERBOSITY
=
3000
;
my
$VERBOSITY
=
3000
;
my
$DEFAULT_INFO
=
4000
;
my
$DEFAULT_INFO
=
4000
;
...
@@ -435,6 +449,52 @@ sub deprecate {
...
@@ -435,6 +449,52 @@ sub deprecate {
$DEPRECATED
{"
$line
:
$file
"}
=
1
;
$DEPRECATED
{"
$line
:
$file
"}
=
1
;
}
}
=head2 try/catch
Arg [1] : anonymous subroutine
the block to be tried
Arg [2] : return value of the catch function
Example : use Bio::EnsEMBL::Utils::Exception qw(throw try catch)
The syntax is:
try { block1 } catch { block2 };
{ block1 } is the 1st argument
catch { block2 } is the 2nd argument
e.g.
try {
throw("this is an exception with a stack trace");
} catch {
print "Caught exception:\n$_";
};
In block2, $_ is assigned the value of the first
throw or die statement executed in block 1.
Description: Replaces the classical syntax
eval { block1 };
if ($@) { block2 }
by a more confortable one.
In the try/catch syntax, the original $@ is in $_ in the catch subroutine.
This try/catch implementation is a copy and paste from
"Programming Perl" 3rd Edition, July 2000, by L.Wall, T. Christiansen
& J. Orwant. p227, and is only possible because of the possibility of
subroutine prototypes.
Returntype : implemented by the catch block
Exceptions : none
Caller : general
=cut
sub
try
(&$) {
my
(
$try
,
$catch
)
=
@_
;
eval
{
&$try
};
if
(
$@
)
{
chop
$@
;
local
$_
=
$@
;
&$catch
;
}
}
sub
catch
(&) {
shift
;
}
1
;
1
;
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment