Proper Way to Catch .NET Exception
4 posts
• Page 1 of 1
Proper Way to Catch .NET Exception
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!
- bluephoenixalpha@codeplex
- Posts: 5
- Joined: January 7th, 2012, 8:57 pm
RE: Proper Way to Catch .NET Exception
Hi,
unfortunately this is not currently supported, but I checked-in the modification that allows this few minutes ago :-) It will be in the next release and if you want to compile Phalanger from the source code you can download latest source.
You will be able to write following:
try
{
Int32::Parse("aa");
}
catch(System:::Exception $e)
{
echo "CLR Exception: ".($e->Message);
}
unfortunately this is not currently supported, but I checked-in the modification that allows this few minutes ago :-) It will be in the next release and if you want to compile Phalanger from the source code you can download latest source.
You will be able to write following:
try
{
Int32::Parse("aa");
}
catch(System:::Exception $e)
{
echo "CLR Exception: ".($e->Message);
}
- tomasp
- Posts: 46
- Joined: January 7th, 2012, 8:37 pm
RE: Proper Way to Catch .NET Exception
Wow, thank you tomasp... I really appreciate it! I'll get the latest source and do a compile and let you know how it works for me.
- bluephoenixalpha@codeplex
- Posts: 5
- Joined: January 7th, 2012, 8:57 pm
RE: Proper Way to Catch .NET Exception
It worked great! Thanks!
- bluephoenixalpha@codeplex
- Posts: 5
- Joined: January 7th, 2012, 8:57 pm
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 9 guests