Proper Way to Catch .NET Exception

Discussion about the open-source Phalanger [?] project.

Proper Way to Catch .NET Exception

Postby bluephoenixalpha@codeplex » 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!
bluephoenixalpha@codeplex
 
Posts: 5
Joined: January 7th, 2012, 8:57 pm

RE: Proper Way to Catch .NET Exception

Postby tomasp » November 19th, 2006, 1:45 am

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);
}
tomasp
 
Posts: 46
Joined: January 7th, 2012, 8:37 pm

RE: Proper Way to Catch .NET Exception

Postby bluephoenixalpha@codeplex » November 19th, 2006, 5:06 am

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

Postby bluephoenixalpha@codeplex » November 19th, 2006, 6:41 am

It worked great! Thanks!
bluephoenixalpha@codeplex
 
Posts: 5
Joined: January 7th, 2012, 8:57 pm


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 9 guests

User Control Panel

Login

Who is online

In total there are 9 users online :: 0 registered, 0 hidden and 9 guests (based on users active over the past 5 minutes)
Most users ever online was 639 on May 10th, 2024, 11:01 am

Users browsing this forum: No registered users and 9 guests