SlideShare a Scribd company logo
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

Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception Handling
Lemi Orhan Ergin
 
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 & Assertionsphanleson
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
Ashwin Shiv
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
Victer Paul
 
Exception handling in c programming
Exception handling in c programmingException handling in c programming
Exception handling in c programming
Raza Najam
 
Java Exception Handling and Applets
Java Exception Handling and AppletsJava Exception Handling and Applets
Java Exception Handling and Applets
Tanmoy Roy
 
Exception handling
Exception handlingException handling
Exception handlingRavi Sharda
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
MaqdamYasir
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Pratik Soares
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handlingDeepak Sharma
 
Exception Handling
Exception HandlingException Handling
Exception Handling
Reddhi Basu
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15Kumar
 
Exception handling
Exception handling Exception handling
Exception handling
M Vishnuvardhan Reddy
 
Exception handling
Exception handlingException handling
Exception handling
Raja Sekhar
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
Nuha Noor
 
Parallel Lint
Parallel LintParallel Lint
Parallel Lint
PVS-Studio
 
Exception handling
Exception handlingException handling
Exception handling
PhD Research Scholar
 
Python exceptions
Python exceptionsPython exceptions
Python exceptions
rikbyte
 

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 javascriptPhúc Đỗ
 
Geographic Computation in Perl
Geographic Computation in PerlGeographic Computation in Perl
Geographic Computation in Perl
Ian Kluft
 
Command Line Arguments with Getopt::Long
Command Line Arguments with Getopt::LongCommand Line Arguments with Getopt::Long
Command Line Arguments with Getopt::Long
Ian Kluft
 
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
Ian Kluft
 
Geographic Computation in Perl
Geographic Computation in PerlGeographic Computation in Perl
Geographic Computation in Perl
Ian Kluft
 
Aerospace applications of Perl
Aerospace applications of PerlAerospace applications of Perl
Aerospace applications of Perl
Ian Kluft
 
Black Rock Desert Impact Theory
Black Rock Desert Impact TheoryBlack Rock Desert Impact Theory
Black Rock Desert Impact Theory
Ian Kluft
 

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
 
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
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
Bharath K
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Kavitha713564
 
Making Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF UsableMaking Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF Usable
Open Networking Summit
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
JavabynataraJ
 
Perl exceptions lightning talk
Perl exceptions lightning talkPerl exceptions lightning talk
Perl exceptions lightning talkPeter Edwards
 
JAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdfJAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdf
Prof. Dr. K. Adisesha
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
Elizabeth alexander
 
Exception handling
Exception handlingException handling
Exception handling
Muthukumaran Subramanian
 
Exception handling
Exception handlingException handling
Exception handling
zindadili
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym 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
 
Core java
Core javaCore java
Core java
Mallikarjuna G D
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
AKSHAYBHABAD5
 
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
2022002857mbit
 
Exception handling
Exception handlingException handling
Exception handling
Karthik Sekar
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
rishisingh190
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
siragezeynu
 
PHP - Introduction to PHP Error Handling
PHP -  Introduction to PHP Error HandlingPHP -  Introduction to PHP Error Handling
PHP - Introduction to PHP Error Handling
Vibrant Technologies & Computers
 

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
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
 
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
 

More from Ian Kluft

"#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
Ian Kluft
 
Secure Coding in Perl
Secure Coding in PerlSecure Coding in Perl
Secure Coding in Perl
Ian Kluft
 
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
Ian Kluft
 
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
Ian Kluft
 
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
Ian Kluft
 
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
Ian Kluft
 
Code Generation in Perl
Code Generation in PerlCode Generation in Perl
Code Generation in Perl
Ian Kluft
 
Pacificon 200905
Pacificon 200905Pacificon 200905
Pacificon 200905
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

Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

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!