Fix for error casting and exception compatibility.