Proper Way to Catch .NET Exception
Posted: November 14th, 2006, 3:46 am
What is the proper way to catch a .NET exception in Phalanger code?
To clarify, a method in my app makes a database call and populates a DataTable (which later is consumed by a DataGridView control. The relavent code is:
private function DBQuery($queryString) {
try {
$conn = $this->DBConnect();
$dataTable = new DataTable();
$dataAdapter = new FbDataAdapter($queryString, $conn);
$dataAdapter->Fill($dataTable);
$this->DBClose($conn);
return $dataTable;
}
catch (Exception $e) {
MessageBox::Show("Error in SQL query. Please correct and " .
"try again.", "Error", MessageBoxButtons::OK,
MessageBoxIcon::Error);
return null;
}
}
How do I catch any .NET exceptions that may be thrown by the connection, data adapter, or whatever? The code above doesn't seem to catch them (perhaps it will only catch a PHP Exception?). Thinking along those lines, I've also tried System:::Exception but have had no luck. Perhaps I have to list the particular Exception class... but that doesn't seem right it wouldn't traverse up the inheritence tree. What am I missing? What is the proper way to do this?
Thanks in advance!
To clarify, a method in my app makes a database call and populates a DataTable (which later is consumed by a DataGridView control. The relavent code is:
private function DBQuery($queryString) {
try {
$conn = $this->DBConnect();
$dataTable = new DataTable();
$dataAdapter = new FbDataAdapter($queryString, $conn);
$dataAdapter->Fill($dataTable);
$this->DBClose($conn);
return $dataTable;
}
catch (Exception $e) {
MessageBox::Show("Error in SQL query. Please correct and " .
"try again.", "Error", MessageBoxButtons::OK,
MessageBoxIcon::Error);
return null;
}
}
How do I catch any .NET exceptions that may be thrown by the connection, data adapter, or whatever? The code above doesn't seem to catch them (perhaps it will only catch a PHP Exception?). Thinking along those lines, I've also tried System:::Exception but have had no luck. Perhaps I have to list the particular Exception class... but that doesn't seem right it wouldn't traverse up the inheritence tree. What am I missing? What is the proper way to do this?
Thanks in advance!