SlideShare a Scribd company logo
1 of 44
Exceptional Exceptions
with @LlewellynFalco & @JamesRCounts
http://youtu.be/k6C_HjWr3Nk?t=3m30s
Eddie Izzard’s printer
Rules
1. All code must compile
2. All exceptions must be thrown because of standard calls to the .Net BCL
3. All improvements must be possible
Today’s Goal
The next time you write
throw new Exception(…);
…you will remember this talk
The route to null evil
11
12
13
14
var a = Router.GetRoute("A");
var b = Router.GetRoute("B");
var c = Router.GetRoute("C");
var result = new Helper(a.From, b.To, c.ViaProxy).Send();
System.NullReferenceException: Object reference not set to an instance
of an object.
at ExceptionalExamples.UnitTests.NullRef() in UnitTest1.cs: line 14
What is null?
A) a
B) b
C) c
D) I don’t know
IL_0028: ldloc.1
IL_0029: callvirt instance object ExceptionalExamples.Route::get_To()
Null reference while executing: Route.To
throw new NullReferenceException(
"Null reference while executing: {0}.{1}",
m.ClassName,
m.MethodSignature());
throw new NullReferenceException(“Object reference not set to an instance of an object.”)
Object reference not set to an instance of an object.
11
12
13
14
var a = Router.GetRoute("A");
var b = Router.GetRoute("B");
var c = Router.GetRoute("C");
var result = new Helper(a.From, b.To, c.ViaProxy).Send();
System.NullReferenceException:
Null reference while executing: Route.To
at ExceptionalExamples.UnitTests.NullRef() in UnitTest1.cs: line 14
What is null?
A) a
B) b
C) c
D) I don’t know
This exception proves the rule…
“Print variable values
in your error messages”
…to give the confused coder some guidance
A heapful of rectangles
System.OutOfMemoryException: Out of memory.
at LinearGradientBrush..ctor(Point p1, Point p2, Color c1, Color c2)
at MyForm.OnPaint(PaintEventArgs e) in c:...UnitTest1.cs:line 64
at Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at Control.OnPrint(PaintEventArgs e)
What went wrong?
A) 10,000 rectangles
B) Brush too big
C) Garbage Collection
D) Other
58
59
60
61
62
63
64
65
66
67
for (var i = 0; i < 10000; i++)
{
int w = random.Next(this.Width);
int h = random.Next(this.Height);
var start = new Point(0, 0);
var end = new Point(w, h);
var b = new LinearGradientBrush(start, end, Color.Red, Color.Blue);
var rect = new Rectangle(random.Next(Width), random.Next(Height), w, h);
e.Graphics.FillRectangle(b, rect);
}
A) new LinearGradientBrush(new Point(0, 0), new Point(w, h), Color.Red, Color.Blue);
B) new LinearGradientBrush(new Rectangle(0, 0, w, h), Color.Red, Color.Blue, 1.0f);
Rectangle '{X=0,Y=0,Width=189,Height=0}' cannot have a width or height equal to 0.
throw new ArgumentException(
@"Rectangle ‘{{X={0},Y={1},Width={2},Height={3}}}'
cannot have a width or height equal to 0.",
start.X, start.Y, end.X - start.X, end.Y - start.Y);
throw new OutOfMemoryException(“Out of memory.”)
Out of memory
Rectangle '{X=0,Y=0,Width=189,Height=0}' cannot have a width or height
equal to 0.
at LinearGradientBrush..ctor(Point p1, Point p2, Color c1, Color c2)
at MyForm.OnPaint(PaintEventArgs e) in c:...UnitTest1.cs:line 64
at Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at Control.OnPrint(PaintEventArgs e)
What went wrong?
A) 10,000 rectangles
B) Brush too big
C) Garbage Collection
D) Other
58
59
60
61
62
63
64
65
66
67
for (var i = 0; i < 10000; i++)
{
int w = random.Next(this.Width);
int h = random.Next(this.Height);
var start = new Point(0, 0);
var end = new Point(w, h);
var b = new LinearGradientBrush(start, end, Color.Red, Color.Blue);
var rect = new Rectangle(random.Next(Width), random.Next(Height), w, h);
e.Graphics.FillRectangle(b, rect);
}
Height is 0
This exception proves the rule…
“If the framework gives you bad
exceptions, throw better ones”
…to give the confused coder some guidance
This exception proves the rule…
“Print other variables to provide context”
…to give the confused coder some guidance
Rectangle '{X=0,Y=0,Width=189,Height=0}'
Cast into the (Void)
System.InvalidCastException: At least one element in the source array could not be cast down
to the destination array type.
at System.Array.Copy(Array s, Array d, Int32 l)
at UnitTests.ArrayCopy() in UnitTest1.cs: line 13
What doesn’t fit?
A) Button
B) Form
C) ToolTip
D) I don’t know
11
12
13
Component[] from = { new Button(), new Form(), new ToolTip(), };
Component[] to = new Collage().GetMemories();
Array.Copy(from, to, from.Length);
<Form> could not be cast to destination array type <Control[]>
throw new InvalidCastException(
"<{0}> could not be cast to destination array type <{1}>",
element.GetType().Name, to.GetType().Name);
throw new InvalidCastException (“…text…”)
At least one element in the source array could not be cast down to
the destination array type.
Array.Copy(from, to, from.Length);13
System.InvalidCastException: <Form> could not be cast to destination array type <Control[]>
at System.Array.Copy(Array s, Array d, Int32 l)
at UnitTests.ArrayCopy() in UnitTest1.cs: line 13
What doesn’t fit?
A) Button
B) Form
C) ToolTip
D) I don’t know
11
12
13
Component[] from = { new Button(), new Form(), new ToolTip(), };
Component[] to = new Collage().GetMemories();
Array.Copy(from, to, from.Length);
This exception proves the rule…
“Runtime details make it clear where the
error comes from”
…to give the confused coder some guidance
A date with a parser
System.FormatException: The string was not recognized as a valid
DateTime. There is an unknown word starting at index 7.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at System.DateTime.Parse(String s)
at ExceptionalExamples.UnitTests.DateTimeParse() in UnitTest1.cs: line 75
How do you need to sanitize the date?
A) Include CultureInfo
B) Remove “th”
C) Only use first three letters of the month
D) Other
75 var dateTime = DateTime.Parse(form.Date);
Cannot parse "March 6th 2010“ at index 7
Valid formats include:
"<Month> <Day> <Year>" => “January 14 2010”
"<Month>/<Day>/<Year>" => “1/14/2010”
"<Year>-<Month>-<Day>" => “2010-01-24”
throw new FormatException(@"Cannot parse '{0}' at index {1}
Valid formats include: {2}",
input, 7, tldr);
throw new FormatException (“…text…” + index)
The string was not recognized as a valid DateTime. There is an
unknown word starting at index 7
75 var dateTime = DateTime.Parse(form.Date);
75
System.FormatException: Cannot parse "March 6th 2010" at index 7
Valid formats include:
"<Month> <Day> <Year>" => "January 14 2010"
"<Month>/<Day>/<Year>" => "1/14/2010"
"<Year>-<Month>-<Day>" => "2010-01-24"
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at System.DateTime.Parse(String s)
at ExceptionalExamples.UnitTests.DateTimeParse() in UnitTest1.cs: line 75
How do you need to sanitize the date?
A) Include CultureInfo
B) Remove “th”
C) Only us first three letters of the month
D) Other
var dateTime = DateTime.Parse(form.Date);
This exception proves the rule…
“Show tl;dr examples if
particular formats are required”
…to give the confused coder some guidance
Touching your privates
in public
82
83
84
85
86
System.MissingMethodException:
Method 'System.Windows.Forms.ButtonBase.GetFlag' not found.
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, …)
at ExceptionalExamples.UnitTests.ButtonAnimation() in UnitTest1.cs: line 85
What went wrong?
A) Not on ButtonBase
B) Wrong parameters
C) Docs are out of date
D) Other
var su = new SignUpPrompt();
su.Advertise();
var pb = new PrivateObject(su.BuyButton, new PrivateType(typeof(ButtonBase)));
var isAnimating = (bool)pb.Invoke("GetFlag", new[] { 0x0010 });
Assert.IsTrue(isAnimating);
private bool GetFlag(int flag)
Cannot find method: GetFlag(int[]).
Possible methods starting with “G” are:
GetFlag(int)
GetPreferedSizeCore(Size)
Common Fixes
If method not listed it might be on a base class
i.e. new PrivateObject(o, new PrivateType(typeof(BaseClass)))
If method is listed check your parameter list
i.e. p.Invoke(“MethodName”, param1, param2)
throw new MissingMethodException (“…text…” + method + “…text…”)
Method 'System.Windows.Forms.ButtonBase.GetFlag' not found.
85 var isAnimating = (bool)pb.Invoke("GetFlag", new[] { 0x0010 });
throw new MissingMethodException(@"Cannot find method: {0}.
Possible methods starting with “{1}” are:n{2}
Common Fixesn{3}“,
method, method[0], this.GetMethodsStartingWith(method[0]),
commonFixes);
82
83
84
85
86
System.MissingMethodException:
Cannot find method: GetFlag(int[]).
Possible methods starting with “G” are:
GetFlag(int)
GetPreferedSizeCore(Size)
Common Fixes
If method not listed it might be on a base class
i.e. new PrivateObject(o, new PrivateType(typeof(BaseClass)))
If method is listed check your parameter list
i.e. p.Invoke(“MethodName”, param1, param2)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, …)
at ExceptionalExamples.UnitTests.ButtonAnimation() in UnitTest1.cs: line 85
What went wrong?
A) Not on ButtonBase
B) Wrong parameters
C) Docs are out of date
D) Other
var su = new SignUpPrompt();
su.Advertise();
var pb = new PrivateObject(su.BuyButton, new PrivateType(typeof(ButtonBase)));
var isAnimating = (bool)pb.Invoke("GetFlag", new[] { 0x0010 });
Assert.IsTrue(isAnimating);
This exception proves the rule…
“Don’t hold back,
You don’t know which clue will help”
…to give the confused coder some guidance
82
83
84
85
86
System.MissingMethodException:
Cannot find method: GetFlag(int).
Possible methods starting with “G” are:
<none>
Common Fixes
If method not listed it might be on a base class
i.e. new PrivateObject(o, new PrivateType(typeof(BaseClass)))
If method is listed check your parameter list
i.e. p.Invoke(“MethodName”, param1, param2)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, …)
at ExceptionalExamples.UnitTests.ButtonAnimation() in UnitTest1.cs: line 85
What went wrong?
A) Not on Button
B) Wrong parameters
C) Docs are out of date
D) Other
var su = new SignUpPrompt();
su.Advertise();
var pb = new PrivateObject(su.BuyButton);
var isAnimating = (bool)pb.Invoke("GetFlag", 0x0010);
Assert.IsTrue(isAnimating);
Don’t disturb the
natives
…or Dynamically Lost Library
82
...
100
101
System.DllNotFoundException:
Unable to load DLL 'libsvn_client-1-0.dll':
The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
at ExceptionalExamples.NativeDll.svn_client_info()
at ExceptionalExamples.UnitTests.NativeTest() in UnitTest1.cs: line 82
Why can’t we find the DLL?
A) Wrong File Permissions
B) Wrong Working Directory
C) Wrong Processor Arch
D) Other
NativeDll.svn_client_info();
[DllImport("libsvn_client-1-0.dll")]
public static extern int svn_client_info();
06/25/2014 09:59 PM 10,240 ExceptionalExamples.dll
06/03/2014 06:11 AM 255,849 libsvn_client-1-0.dll
2 File(s) 266,089 bytes
Problems loading dependencies for
“libsvn_client-1-0.dll”.
Could not find dependency: “MSYS-1.0.dll”
Required libraries:
MSYS-1.0.dll
LIBSVN_DELTA-1-0.DLL
LIBSVN_DIFF-1-0.DLL
LIBAPR-0-0.DLL
LIBSVN_SUBR-1-0.DLL
throw new DllNotFoundException (“…text…” + index)
Unable to load DLL 'libsvn_client-1-0.dll':
The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
100 [DllImport("libsvn_client-1-0.dll")]
throw new DllNotFoundException(@"Problems loading
dependencies for '{0}'.
Could not find dependency: '{1}'
Required libraries:n{2}",
dll,
missingDependancy,
allDependancies.ToReadableString());
82
...
100
101
System.DllNotFoundException:
Problems loading dependencies for “libsvn_client-1-0.dll”.
Could not find dependency: “MSYS-1.0.dll”
Required libraries:
MSYS-1.0.dll
LIBSVN_DELTA-1-0.DLL
LIBSVN_DIFF-1-0.DLL
LIBAPR-0-0.DLL
LIBSVN_SUBR-1-0.DLL
at ExceptionalExamples.NativeDll.svn_client_info()
at ExceptionalExamples.UnitTests.NativeTest() in UnitTest1.cs: line 82
Why can’t we find the DLL?
A) Wrong File Permissions
B) Wrong Working Directory
C) Wrong Processor Arch
D) Other
NativeDll.svn_client_info();
[DllImport("libsvn_client-1-0.dll")]
public static extern int svn_client_info();
06/25/2014 09:59 PM 10,240 ExceptionalExamples.dll
06/03/2014 06:11 AM 255,849 libsvn_client-1-0.dll
2 File(s) 266,089 bytes
This exception proves the rule…
“Highlight root causes”
…to give the confused coder some guidance
Use variable values
Wrap bad exceptions
Provide context
Show runtime details
tl;dr examples
Extra information
Highlight root causes
Approval Tests 20 episode youtube series
pluralsight.com/kids
Contact Information
@LlewellynFalco
http://LlewellynFalco.Blogspot.com
@JamesRCounts
http://IHadThisIdeaOnce.com
Slides at http://lfal.co/ExceptionalExceptions

More Related Content

What's hot

VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07HUST
 
IP project for class 12 cbse
IP project for class 12 cbseIP project for class 12 cbse
IP project for class 12 cbsesiddharthjha34
 
Standford 2015 week9
Standford 2015 week9Standford 2015 week9
Standford 2015 week9彼得潘 Pan
 
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...Andrés Viedma Peláez
 
Common Pitfalls Experienced in Java
Common Pitfalls Experienced in JavaCommon Pitfalls Experienced in Java
Common Pitfalls Experienced in JavaExist
 
The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194Mahmoud Samir Fayed
 
Standford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, ViewsStandford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, Views彼得潘 Pan
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثةجامعة القدس المفتوحة
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation systemPrashant Sharma
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعةشرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعةجامعة القدس المفتوحة
 

What's hot (17)

VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07
 
C programs
C programsC programs
C programs
 
IP project for class 12 cbse
IP project for class 12 cbseIP project for class 12 cbse
IP project for class 12 cbse
 
Pre zen ta sion
Pre zen ta sionPre zen ta sion
Pre zen ta sion
 
Ann
AnnAnn
Ann
 
Data Structure
Data StructureData Structure
Data Structure
 
Standford 2015 week9
Standford 2015 week9Standford 2015 week9
Standford 2015 week9
 
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
 
Common Pitfalls Experienced in Java
Common Pitfalls Experienced in JavaCommon Pitfalls Experienced in Java
Common Pitfalls Experienced in Java
 
The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194
 
Standford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, ViewsStandford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, Views
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation system
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعةشرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
 

Similar to Exceptional exceptions

Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentalsKapish Joshi
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical FileFahad Shaikh
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstractionIntro C# Book
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxgitagrimston
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
Review questions and answers
Review questions and answersReview questions and answers
Review questions and answersIIUM
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer developmentAndrey Karpov
 

Similar to Exceptional exceptions (20)

Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docx
 
Java file
Java fileJava file
Java file
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
Review questions and answers
Review questions and answersReview questions and answers
Review questions and answers
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
Java practical
Java practicalJava practical
Java practical
 

More from Llewellyn Falco

Test driven development done well
Test driven development done wellTest driven development done well
Test driven development done wellLlewellyn Falco
 
Do not use the greater than sign in programming
Do not use the greater than sign in programmingDo not use the greater than sign in programming
Do not use the greater than sign in programmingLlewellyn Falco
 
The falco technical coaching framework
The falco technical coaching frameworkThe falco technical coaching framework
The falco technical coaching frameworkLlewellyn Falco
 
Developing design sense of code smells
Developing design sense of code smellsDeveloping design sense of code smells
Developing design sense of code smellsLlewellyn Falco
 
Exploratory and Unit Testing
Exploratory and Unit TestingExploratory and Unit Testing
Exploratory and Unit TestingLlewellyn Falco
 
Increase testability with code seams
Increase testability with code seamsIncrease testability with code seams
Increase testability with code seamsLlewellyn Falco
 
Approval testing from basic to advanced
Approval testing   from basic to advancedApproval testing   from basic to advanced
Approval testing from basic to advancedLlewellyn Falco
 
Strategy agile games 2015
Strategy   agile games 2015Strategy   agile games 2015
Strategy agile games 2015Llewellyn Falco
 
Getting existing code under tests
Getting existing code under testsGetting existing code under tests
Getting existing code under testsLlewellyn Falco
 

More from Llewellyn Falco (20)

Lets connect linked_in
Lets connect linked_inLets connect linked_in
Lets connect linked_in
 
Test driven development done well
Test driven development done wellTest driven development done well
Test driven development done well
 
Do not use the greater than sign in programming
Do not use the greater than sign in programmingDo not use the greater than sign in programming
Do not use the greater than sign in programming
 
Cutting code quickly
Cutting code quicklyCutting code quickly
Cutting code quickly
 
The falco technical coaching framework
The falco technical coaching frameworkThe falco technical coaching framework
The falco technical coaching framework
 
Expressive objects
Expressive objectsExpressive objects
Expressive objects
 
Roi on learning hour
Roi on learning hourRoi on learning hour
Roi on learning hour
 
Mob programming
Mob programmingMob programming
Mob programming
 
Mob testing
Mob testingMob testing
Mob testing
 
Developing design sense of code smells
Developing design sense of code smellsDeveloping design sense of code smells
Developing design sense of code smells
 
10x
10x10x
10x
 
Strong Style Pairing
Strong Style PairingStrong Style Pairing
Strong Style Pairing
 
Exploratory and Unit Testing
Exploratory and Unit TestingExploratory and Unit Testing
Exploratory and Unit Testing
 
Increase testability with code seams
Increase testability with code seamsIncrease testability with code seams
Increase testability with code seams
 
Advanced unit testing
Advanced unit testingAdvanced unit testing
Advanced unit testing
 
The curse of knowledge
The curse of knowledgeThe curse of knowledge
The curse of knowledge
 
Approval testing from basic to advanced
Approval testing   from basic to advancedApproval testing   from basic to advanced
Approval testing from basic to advanced
 
Intentional code
Intentional codeIntentional code
Intentional code
 
Strategy agile games 2015
Strategy   agile games 2015Strategy   agile games 2015
Strategy agile games 2015
 
Getting existing code under tests
Getting existing code under testsGetting existing code under tests
Getting existing code under tests
 

Recently uploaded

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Exceptional exceptions

  • 3. Rules 1. All code must compile 2. All exceptions must be thrown because of standard calls to the .Net BCL 3. All improvements must be possible
  • 4. Today’s Goal The next time you write throw new Exception(…); …you will remember this talk
  • 5. The route to null evil
  • 6. 11 12 13 14 var a = Router.GetRoute("A"); var b = Router.GetRoute("B"); var c = Router.GetRoute("C"); var result = new Helper(a.From, b.To, c.ViaProxy).Send(); System.NullReferenceException: Object reference not set to an instance of an object. at ExceptionalExamples.UnitTests.NullRef() in UnitTest1.cs: line 14 What is null? A) a B) b C) c D) I don’t know
  • 7. IL_0028: ldloc.1 IL_0029: callvirt instance object ExceptionalExamples.Route::get_To() Null reference while executing: Route.To throw new NullReferenceException( "Null reference while executing: {0}.{1}", m.ClassName, m.MethodSignature()); throw new NullReferenceException(“Object reference not set to an instance of an object.”) Object reference not set to an instance of an object.
  • 8. 11 12 13 14 var a = Router.GetRoute("A"); var b = Router.GetRoute("B"); var c = Router.GetRoute("C"); var result = new Helper(a.From, b.To, c.ViaProxy).Send(); System.NullReferenceException: Null reference while executing: Route.To at ExceptionalExamples.UnitTests.NullRef() in UnitTest1.cs: line 14 What is null? A) a B) b C) c D) I don’t know
  • 9. This exception proves the rule… “Print variable values in your error messages” …to give the confused coder some guidance
  • 10. A heapful of rectangles
  • 11. System.OutOfMemoryException: Out of memory. at LinearGradientBrush..ctor(Point p1, Point p2, Color c1, Color c2) at MyForm.OnPaint(PaintEventArgs e) in c:...UnitTest1.cs:line 64 at Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) at Control.OnPrint(PaintEventArgs e) What went wrong? A) 10,000 rectangles B) Brush too big C) Garbage Collection D) Other 58 59 60 61 62 63 64 65 66 67 for (var i = 0; i < 10000; i++) { int w = random.Next(this.Width); int h = random.Next(this.Height); var start = new Point(0, 0); var end = new Point(w, h); var b = new LinearGradientBrush(start, end, Color.Red, Color.Blue); var rect = new Rectangle(random.Next(Width), random.Next(Height), w, h); e.Graphics.FillRectangle(b, rect); }
  • 12. A) new LinearGradientBrush(new Point(0, 0), new Point(w, h), Color.Red, Color.Blue); B) new LinearGradientBrush(new Rectangle(0, 0, w, h), Color.Red, Color.Blue, 1.0f); Rectangle '{X=0,Y=0,Width=189,Height=0}' cannot have a width or height equal to 0. throw new ArgumentException( @"Rectangle ‘{{X={0},Y={1},Width={2},Height={3}}}' cannot have a width or height equal to 0.", start.X, start.Y, end.X - start.X, end.Y - start.Y); throw new OutOfMemoryException(“Out of memory.”) Out of memory
  • 13. Rectangle '{X=0,Y=0,Width=189,Height=0}' cannot have a width or height equal to 0. at LinearGradientBrush..ctor(Point p1, Point p2, Color c1, Color c2) at MyForm.OnPaint(PaintEventArgs e) in c:...UnitTest1.cs:line 64 at Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) at Control.OnPrint(PaintEventArgs e) What went wrong? A) 10,000 rectangles B) Brush too big C) Garbage Collection D) Other 58 59 60 61 62 63 64 65 66 67 for (var i = 0; i < 10000; i++) { int w = random.Next(this.Width); int h = random.Next(this.Height); var start = new Point(0, 0); var end = new Point(w, h); var b = new LinearGradientBrush(start, end, Color.Red, Color.Blue); var rect = new Rectangle(random.Next(Width), random.Next(Height), w, h); e.Graphics.FillRectangle(b, rect); } Height is 0
  • 14. This exception proves the rule… “If the framework gives you bad exceptions, throw better ones” …to give the confused coder some guidance
  • 15. This exception proves the rule… “Print other variables to provide context” …to give the confused coder some guidance Rectangle '{X=0,Y=0,Width=189,Height=0}'
  • 16. Cast into the (Void)
  • 17. System.InvalidCastException: At least one element in the source array could not be cast down to the destination array type. at System.Array.Copy(Array s, Array d, Int32 l) at UnitTests.ArrayCopy() in UnitTest1.cs: line 13 What doesn’t fit? A) Button B) Form C) ToolTip D) I don’t know 11 12 13 Component[] from = { new Button(), new Form(), new ToolTip(), }; Component[] to = new Collage().GetMemories(); Array.Copy(from, to, from.Length);
  • 18. <Form> could not be cast to destination array type <Control[]> throw new InvalidCastException( "<{0}> could not be cast to destination array type <{1}>", element.GetType().Name, to.GetType().Name); throw new InvalidCastException (“…text…”) At least one element in the source array could not be cast down to the destination array type. Array.Copy(from, to, from.Length);13
  • 19. System.InvalidCastException: <Form> could not be cast to destination array type <Control[]> at System.Array.Copy(Array s, Array d, Int32 l) at UnitTests.ArrayCopy() in UnitTest1.cs: line 13 What doesn’t fit? A) Button B) Form C) ToolTip D) I don’t know 11 12 13 Component[] from = { new Button(), new Form(), new ToolTip(), }; Component[] to = new Collage().GetMemories(); Array.Copy(from, to, from.Length);
  • 20. This exception proves the rule… “Runtime details make it clear where the error comes from” …to give the confused coder some guidance
  • 21. A date with a parser
  • 22. System.FormatException: The string was not recognized as a valid DateTime. There is an unknown word starting at index 7. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s) at ExceptionalExamples.UnitTests.DateTimeParse() in UnitTest1.cs: line 75 How do you need to sanitize the date? A) Include CultureInfo B) Remove “th” C) Only use first three letters of the month D) Other 75 var dateTime = DateTime.Parse(form.Date);
  • 23. Cannot parse "March 6th 2010“ at index 7 Valid formats include: "<Month> <Day> <Year>" => “January 14 2010” "<Month>/<Day>/<Year>" => “1/14/2010” "<Year>-<Month>-<Day>" => “2010-01-24” throw new FormatException(@"Cannot parse '{0}' at index {1} Valid formats include: {2}", input, 7, tldr); throw new FormatException (“…text…” + index) The string was not recognized as a valid DateTime. There is an unknown word starting at index 7 75 var dateTime = DateTime.Parse(form.Date);
  • 24.
  • 25. 75 System.FormatException: Cannot parse "March 6th 2010" at index 7 Valid formats include: "<Month> <Day> <Year>" => "January 14 2010" "<Month>/<Day>/<Year>" => "1/14/2010" "<Year>-<Month>-<Day>" => "2010-01-24" at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s) at ExceptionalExamples.UnitTests.DateTimeParse() in UnitTest1.cs: line 75 How do you need to sanitize the date? A) Include CultureInfo B) Remove “th” C) Only us first three letters of the month D) Other var dateTime = DateTime.Parse(form.Date);
  • 26. This exception proves the rule… “Show tl;dr examples if particular formats are required” …to give the confused coder some guidance
  • 28. 82 83 84 85 86 System.MissingMethodException: Method 'System.Windows.Forms.ButtonBase.GetFlag' not found. at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, …) at ExceptionalExamples.UnitTests.ButtonAnimation() in UnitTest1.cs: line 85 What went wrong? A) Not on ButtonBase B) Wrong parameters C) Docs are out of date D) Other var su = new SignUpPrompt(); su.Advertise(); var pb = new PrivateObject(su.BuyButton, new PrivateType(typeof(ButtonBase))); var isAnimating = (bool)pb.Invoke("GetFlag", new[] { 0x0010 }); Assert.IsTrue(isAnimating); private bool GetFlag(int flag)
  • 29. Cannot find method: GetFlag(int[]). Possible methods starting with “G” are: GetFlag(int) GetPreferedSizeCore(Size) Common Fixes If method not listed it might be on a base class i.e. new PrivateObject(o, new PrivateType(typeof(BaseClass))) If method is listed check your parameter list i.e. p.Invoke(“MethodName”, param1, param2) throw new MissingMethodException (“…text…” + method + “…text…”) Method 'System.Windows.Forms.ButtonBase.GetFlag' not found. 85 var isAnimating = (bool)pb.Invoke("GetFlag", new[] { 0x0010 });
  • 30. throw new MissingMethodException(@"Cannot find method: {0}. Possible methods starting with “{1}” are:n{2} Common Fixesn{3}“, method, method[0], this.GetMethodsStartingWith(method[0]), commonFixes);
  • 31. 82 83 84 85 86 System.MissingMethodException: Cannot find method: GetFlag(int[]). Possible methods starting with “G” are: GetFlag(int) GetPreferedSizeCore(Size) Common Fixes If method not listed it might be on a base class i.e. new PrivateObject(o, new PrivateType(typeof(BaseClass))) If method is listed check your parameter list i.e. p.Invoke(“MethodName”, param1, param2) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, …) at ExceptionalExamples.UnitTests.ButtonAnimation() in UnitTest1.cs: line 85 What went wrong? A) Not on ButtonBase B) Wrong parameters C) Docs are out of date D) Other var su = new SignUpPrompt(); su.Advertise(); var pb = new PrivateObject(su.BuyButton, new PrivateType(typeof(ButtonBase))); var isAnimating = (bool)pb.Invoke("GetFlag", new[] { 0x0010 }); Assert.IsTrue(isAnimating);
  • 32. This exception proves the rule… “Don’t hold back, You don’t know which clue will help” …to give the confused coder some guidance
  • 33. 82 83 84 85 86 System.MissingMethodException: Cannot find method: GetFlag(int). Possible methods starting with “G” are: <none> Common Fixes If method not listed it might be on a base class i.e. new PrivateObject(o, new PrivateType(typeof(BaseClass))) If method is listed check your parameter list i.e. p.Invoke(“MethodName”, param1, param2) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, …) at ExceptionalExamples.UnitTests.ButtonAnimation() in UnitTest1.cs: line 85 What went wrong? A) Not on Button B) Wrong parameters C) Docs are out of date D) Other var su = new SignUpPrompt(); su.Advertise(); var pb = new PrivateObject(su.BuyButton); var isAnimating = (bool)pb.Invoke("GetFlag", 0x0010); Assert.IsTrue(isAnimating);
  • 34. Don’t disturb the natives …or Dynamically Lost Library
  • 35. 82 ... 100 101 System.DllNotFoundException: Unable to load DLL 'libsvn_client-1-0.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at ExceptionalExamples.NativeDll.svn_client_info() at ExceptionalExamples.UnitTests.NativeTest() in UnitTest1.cs: line 82 Why can’t we find the DLL? A) Wrong File Permissions B) Wrong Working Directory C) Wrong Processor Arch D) Other NativeDll.svn_client_info(); [DllImport("libsvn_client-1-0.dll")] public static extern int svn_client_info(); 06/25/2014 09:59 PM 10,240 ExceptionalExamples.dll 06/03/2014 06:11 AM 255,849 libsvn_client-1-0.dll 2 File(s) 266,089 bytes
  • 36. Problems loading dependencies for “libsvn_client-1-0.dll”. Could not find dependency: “MSYS-1.0.dll” Required libraries: MSYS-1.0.dll LIBSVN_DELTA-1-0.DLL LIBSVN_DIFF-1-0.DLL LIBAPR-0-0.DLL LIBSVN_SUBR-1-0.DLL throw new DllNotFoundException (“…text…” + index) Unable to load DLL 'libsvn_client-1-0.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) 100 [DllImport("libsvn_client-1-0.dll")]
  • 37. throw new DllNotFoundException(@"Problems loading dependencies for '{0}'. Could not find dependency: '{1}' Required libraries:n{2}", dll, missingDependancy, allDependancies.ToReadableString());
  • 38. 82 ... 100 101 System.DllNotFoundException: Problems loading dependencies for “libsvn_client-1-0.dll”. Could not find dependency: “MSYS-1.0.dll” Required libraries: MSYS-1.0.dll LIBSVN_DELTA-1-0.DLL LIBSVN_DIFF-1-0.DLL LIBAPR-0-0.DLL LIBSVN_SUBR-1-0.DLL at ExceptionalExamples.NativeDll.svn_client_info() at ExceptionalExamples.UnitTests.NativeTest() in UnitTest1.cs: line 82 Why can’t we find the DLL? A) Wrong File Permissions B) Wrong Working Directory C) Wrong Processor Arch D) Other NativeDll.svn_client_info(); [DllImport("libsvn_client-1-0.dll")] public static extern int svn_client_info(); 06/25/2014 09:59 PM 10,240 ExceptionalExamples.dll 06/03/2014 06:11 AM 255,849 libsvn_client-1-0.dll 2 File(s) 266,089 bytes
  • 39. This exception proves the rule… “Highlight root causes” …to give the confused coder some guidance
  • 40. Use variable values Wrap bad exceptions Provide context Show runtime details tl;dr examples Extra information Highlight root causes
  • 41. Approval Tests 20 episode youtube series
  • 42.