Errors and Exception Handling: Tim Bisson
Errors and Exception Handling: Tim Bisson
Errors and Exception Handling: Tim Bisson
Handling
Tim Bisson
Outline for Today
Kernel Development
Debugging, error handling, and virtual machines
Userspace C
Exception handling?
Serial Debugging
Two machines: test and development
Communicate over gdb through serial port
Many systems companies have some form of this
infrastructure
Core dumps
Analyze stack trace off-line
Kernel Development with
Virtual Machines
Virtual machines as test systems - when the break, they
dont panic the host system
Just reboot the virtual machines (like restarting an app)
Parallels, Xen
UML
Run Linux Kernel as a process in Linux
Example using UML
UMLuses SIGSEGV to fault pages into the
UML kernel
Ext4_abort
unrecoverable failures such as journal I/O or ENOMEM
Unconditionally force file system into read-only mode or panic
end:
/* clean up*/
free (data);
return ret_val;
}
Userland C and exception
handling
C doesnt support exception handling
normal process do {
termination }while(++numsamples < NUMSAMPLES && !quit);
}
C++ and Exception Handling
Try-Catch-Throw model
try {
//code that might throw an exception
}
Throwing an Exception
Indicates an exception occurred
Specify one operand
Exception object, if operand thrown is an object
Exception caught by closest handler from try block in which
exception thrown
Control transferred to handler
if (denominator == 0)
throw DivideByZeroException();
void throwException() {
try { // Throw an exception and immediately catch it.
cout << "Function throwException\n";
throw exception();
Output:
} Function throwException
catch( exception e ) {
cout << "Exception handled in function throwException\n"; Exception handled in function throwException
throw; // re-throw exception for further processing
}
Exception handled in main
cout << This should not be print\n; //control never gets here Program control continues after catch in main
}
void main( ) {
try {
throwException();
cout << This should not be print\n; //exception will be thrown
}
catch ( exception e ) {
cout << "Exception handled in main" << endl;
}
cout << "Program control continues after catch in main" << endl;
}