SlideShare a Scribd company logo
1 of 14
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 1 of 14
Exception Handling in Perl
Presented by Ian Kluft
Silicon Valley Perl
July 7, 2011
Santa Clara, California
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 2 of 14
Exception Handling in Perl
Three parts to this presentation
● What is exception handling?
● Exception handling modules for Perl
● Using exception handling in your Perl code
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 3 of 14
What is Exception Handling?
● Method of error handling
● Exception is an error which can be
caught by a calling function
● Exception unrolls function calls
until one catches it
● Contains structured data about
error, not just numeric code
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 4 of 14
Exception Handling in the News
● Don't forget to catch exceptions in your code
● Highest profile example: Ariane 501 accident
● June 4, 1996 in Kourou, French Guiana
● ESA space rocket exploded 36 seconds into flight
● Accident investigators found software crashed on
test bench 36 seconds into simulated flight (!!!)
● Integer counter overflow exception was not caught
● Software was only tested with Ariane 4 flight profile
● Ariane 5 overflowed a horizontal motion counter
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 5 of 14
Causes of Exceptions
● Exceptions may be caused by fatal error in
code or system call
● If the program signals an exception itself, it is
called “throwing” an exception
● Most Perl code uses simple form of throwing
exceptions
open FILE, “foo” or die “open failed: $!”
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 6 of 14
Mechanism of Catching Exceptions
● Exceptions can be caught in Perl with eval()
● This is just showing you how it works
● Don't re-invent the wheel
● There are modules for this
eval {
... code to do something ...
};
if ($@) {
handle_error($@);
}
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 7 of 14
Exception Handling Modules
CPAN has many exception handling modules
● Exception::Class is recommended, shown here
● Exception::Lite also currently maintained
● Error adds try/catch style to Perl syntax
● Exception::System – catch system call errors
● Exception (not currently maintained)
● Class::Throwable (not currently maintained)
● Some module sets use own exception handling
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 8 of 14
Exception::Class
● Exceptions are classes inheriting from
Exception::Class or your subclasses of it
● You can organize exceptions hierarchically
● Exception::Class::Base offers handler code
● Using classes sets exceptions at compile time
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 9 of 14
Exception::Class declaration
From manual page:
use Exception::Class
( 'MyException',
'AnotherException' =>
{ isa => 'MyException' },
'YetAnotherException' =>
{ isa => 'AnotherException',
description => 'These exceptions are related to IPC' },
'ExceptionWithFields' =>
{ isa => 'YetAnotherException',
fields => [ 'grandiosity', 'quixotic' ],
alias => 'throw_fields',
},
);
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 10 of 14
Exception::Class usage
From manual page:
# try
eval { MyException->throw( error => 'I feel funny.' ) };
my $e;
# catch
if ( $e = Exception::Class->caught('MyException') ) {
warn $e->error, "n", $e->trace->as_string, "n";
warn join ' ', $e->euid, $e->egid, $e->uid, $e->gid,
$e->pid, $e->time;
exit;
} elsif ( $e = Exception::Class->caught('ExceptionWithFields') ) {
$e->quixotic ? do_something_wacky() : do_something_sane();
} else {
$e = Exception::Class->caught();
ref $e ? $e->rethrow : die $e;
}
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 11 of 14
Wrapping main in exception handler
● Good practice... no! This is a best practice.
● To catch all exceptions, make main() an
exception handler wrapper
● Adapt manual page code from previous slide
● Catch Exception::Class exceptions
● Then report unknown errors, like die()
● More graceful exit for program
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 12 of 14
Building depth into error reporting
● Exception classes can be configured to collect
stack traces
● Data structures can be passed from error
recognition point to error reporting code
● Exception::Class::DBI integrates w/ DBI code
● Catch unexpected database errors
● Make a sane error report to user
● Mail notification about database errors to DBAs
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 13 of 14
Exceptions with text descriptions
● All errors can and should have text descriptions
● Error reporting and documentation can be
much more organized
● Extract error documentation from Perl code
● Document for engineers what causes that error
● Document for user/operator what to do when
they see that error
● Document for support dept what it means when
customer calls with that error
Presented at SVPerl
July 7, 2011
Exception Handling in Perl
By Ian Kluft
Slide 14 of 14
Perl Exception Handling: go do it!
● Everything is easier when you design it in
● But this can be added to existing code
● First, add exception-handler wrapper(s)
● Then, define exception classes as needed
● Replace error codes with throwing exceptions
● Both can exist during transition
● Goal: get rid of numeric error codes!

More Related Content

What's hot

Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertions
phanleson
 
Exception handling
Exception handlingException handling
Exception handling
Ravi Sharda
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handling
Deepak Sharma
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
Kumar
 

What's hot (20)

Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception Handling
 
Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertions
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
 
Exception handling in c programming
Exception handling in c programmingException handling in c programming
Exception handling in c programming
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Java Exception Handling and Applets
Java Exception Handling and AppletsJava Exception Handling and Applets
Java Exception Handling and Applets
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
 
Exception handling
Exception handlingException handling
Exception handling
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handling
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
 
Exception handling
Exception handling Exception handling
Exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Parallel Lint
Parallel LintParallel Lint
Parallel Lint
 
Exception handling
Exception handlingException handling
Exception handling
 
Python exceptions
Python exceptionsPython exceptions
Python exceptions
 

Viewers also liked

08. session 08 intoduction to javascript
08. session 08   intoduction to javascript08. session 08   intoduction to javascript
08. session 08 intoduction to javascript
Phúc Đỗ
 

Viewers also liked (7)

08. session 08 intoduction to javascript
08. session 08   intoduction to javascript08. session 08   intoduction to javascript
08. session 08 intoduction to javascript
 
Geographic Computation in Perl
Geographic Computation in PerlGeographic Computation in Perl
Geographic Computation in Perl
 
Command Line Arguments with Getopt::Long
Command Line Arguments with Getopt::LongCommand Line Arguments with Getopt::Long
Command Line Arguments with Getopt::Long
 
Stratofox Aerospace Tracking Team presentation at Space Access 2013
Stratofox Aerospace Tracking Team presentation at Space Access 2013Stratofox Aerospace Tracking Team presentation at Space Access 2013
Stratofox Aerospace Tracking Team presentation at Space Access 2013
 
Geographic Computation in Perl
Geographic Computation in PerlGeographic Computation in Perl
Geographic Computation in Perl
 
Aerospace applications of Perl
Aerospace applications of PerlAerospace applications of Perl
Aerospace applications of Perl
 
Black Rock Desert Impact Theory
Black Rock Desert Impact TheoryBlack Rock Desert Impact Theory
Black Rock Desert Impact Theory
 

Similar to Exception Handling in Perl

Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
Perl exceptions lightning talk
Perl exceptions lightning talkPerl exceptions lightning talk
Perl exceptions lightning talk
Peter Edwards
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
Vadym Lotar
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
AboMohammad10
 

Similar to Exception Handling in Perl (20)

Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
 
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
CS3391 -OOP -UNIT – III  NOTES FINAL.pdfCS3391 -OOP -UNIT – III  NOTES FINAL.pdf
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Making Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF UsableMaking Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF Usable
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Perl exceptions lightning talk
Perl exceptions lightning talkPerl exceptions lightning talk
Perl exceptions lightning talk
 
JAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdfJAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdf
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
 
Core java
Core javaCore java
Core java
 
Java Exception Handling and examples about it
Java Exception Handling and examples about itJava Exception Handling and examples about it
Java Exception Handling and examples about it
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
PHP - Introduction to PHP Error Handling
PHP -  Introduction to PHP Error HandlingPHP -  Introduction to PHP Error Handling
PHP - Introduction to PHP Error Handling
 
Handling Exceptions In C & C++[Part A]
Handling Exceptions In C & C++[Part A]Handling Exceptions In C & C++[Part A]
Handling Exceptions In C & C++[Part A]
 

More from Ian Kluft

More from Ian Kluft (8)

"#AprilFools Hijinks" at SVPerl April 2021 meeting
"#AprilFools Hijinks" at SVPerl April 2021 meeting"#AprilFools Hijinks" at SVPerl April 2021 meeting
"#AprilFools Hijinks" at SVPerl April 2021 meeting
 
Secure Coding in Perl
Secure Coding in PerlSecure Coding in Perl
Secure Coding in Perl
 
New Perl module Container::Buildah - SVPerl presentation
New Perl module Container::Buildah - SVPerl presentationNew Perl module Container::Buildah - SVPerl presentation
New Perl module Container::Buildah - SVPerl presentation
 
Securing a Raspberry Pi and other DIY IoT devices
Securing a Raspberry Pi and other DIY IoT devicesSecuring a Raspberry Pi and other DIY IoT devices
Securing a Raspberry Pi and other DIY IoT devices
 
Best Practices for Recovering Rocket & Balloon Payloads
Best Practices for Recovering Rocket & Balloon PayloadsBest Practices for Recovering Rocket & Balloon Payloads
Best Practices for Recovering Rocket & Balloon Payloads
 
PiFlash: Linux utility to flash SD cards for Raspberry Pi computers
PiFlash: Linux utility to flash SD cards for Raspberry Pi computersPiFlash: Linux utility to flash SD cards for Raspberry Pi computers
PiFlash: Linux utility to flash SD cards for Raspberry Pi computers
 
Code Generation in Perl
Code Generation in PerlCode Generation in Perl
Code Generation in Perl
 
Pacificon 200905
Pacificon 200905Pacificon 200905
Pacificon 200905
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 

Exception Handling in Perl

  • 1. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 1 of 14 Exception Handling in Perl Presented by Ian Kluft Silicon Valley Perl July 7, 2011 Santa Clara, California
  • 2. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 2 of 14 Exception Handling in Perl Three parts to this presentation ● What is exception handling? ● Exception handling modules for Perl ● Using exception handling in your Perl code
  • 3. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 3 of 14 What is Exception Handling? ● Method of error handling ● Exception is an error which can be caught by a calling function ● Exception unrolls function calls until one catches it ● Contains structured data about error, not just numeric code
  • 4. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 4 of 14 Exception Handling in the News ● Don't forget to catch exceptions in your code ● Highest profile example: Ariane 501 accident ● June 4, 1996 in Kourou, French Guiana ● ESA space rocket exploded 36 seconds into flight ● Accident investigators found software crashed on test bench 36 seconds into simulated flight (!!!) ● Integer counter overflow exception was not caught ● Software was only tested with Ariane 4 flight profile ● Ariane 5 overflowed a horizontal motion counter
  • 5. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 5 of 14 Causes of Exceptions ● Exceptions may be caused by fatal error in code or system call ● If the program signals an exception itself, it is called “throwing” an exception ● Most Perl code uses simple form of throwing exceptions open FILE, “foo” or die “open failed: $!”
  • 6. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 6 of 14 Mechanism of Catching Exceptions ● Exceptions can be caught in Perl with eval() ● This is just showing you how it works ● Don't re-invent the wheel ● There are modules for this eval { ... code to do something ... }; if ($@) { handle_error($@); }
  • 7. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 7 of 14 Exception Handling Modules CPAN has many exception handling modules ● Exception::Class is recommended, shown here ● Exception::Lite also currently maintained ● Error adds try/catch style to Perl syntax ● Exception::System – catch system call errors ● Exception (not currently maintained) ● Class::Throwable (not currently maintained) ● Some module sets use own exception handling
  • 8. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 8 of 14 Exception::Class ● Exceptions are classes inheriting from Exception::Class or your subclasses of it ● You can organize exceptions hierarchically ● Exception::Class::Base offers handler code ● Using classes sets exceptions at compile time
  • 9. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 9 of 14 Exception::Class declaration From manual page: use Exception::Class ( 'MyException', 'AnotherException' => { isa => 'MyException' }, 'YetAnotherException' => { isa => 'AnotherException', description => 'These exceptions are related to IPC' }, 'ExceptionWithFields' => { isa => 'YetAnotherException', fields => [ 'grandiosity', 'quixotic' ], alias => 'throw_fields', }, );
  • 10. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 10 of 14 Exception::Class usage From manual page: # try eval { MyException->throw( error => 'I feel funny.' ) }; my $e; # catch if ( $e = Exception::Class->caught('MyException') ) { warn $e->error, "n", $e->trace->as_string, "n"; warn join ' ', $e->euid, $e->egid, $e->uid, $e->gid, $e->pid, $e->time; exit; } elsif ( $e = Exception::Class->caught('ExceptionWithFields') ) { $e->quixotic ? do_something_wacky() : do_something_sane(); } else { $e = Exception::Class->caught(); ref $e ? $e->rethrow : die $e; }
  • 11. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 11 of 14 Wrapping main in exception handler ● Good practice... no! This is a best practice. ● To catch all exceptions, make main() an exception handler wrapper ● Adapt manual page code from previous slide ● Catch Exception::Class exceptions ● Then report unknown errors, like die() ● More graceful exit for program
  • 12. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 12 of 14 Building depth into error reporting ● Exception classes can be configured to collect stack traces ● Data structures can be passed from error recognition point to error reporting code ● Exception::Class::DBI integrates w/ DBI code ● Catch unexpected database errors ● Make a sane error report to user ● Mail notification about database errors to DBAs
  • 13. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 13 of 14 Exceptions with text descriptions ● All errors can and should have text descriptions ● Error reporting and documentation can be much more organized ● Extract error documentation from Perl code ● Document for engineers what causes that error ● Document for user/operator what to do when they see that error ● Document for support dept what it means when customer calls with that error
  • 14. Presented at SVPerl July 7, 2011 Exception Handling in Perl By Ian Kluft Slide 14 of 14 Perl Exception Handling: go do it! ● Everything is easier when you design it in ● But this can be added to existing code ● First, add exception-handler wrapper(s) ● Then, define exception classes as needed ● Replace error codes with throwing exceptions ● Both can exist during transition ● Goal: get rid of numeric error codes!