473,379 Members | 1,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Empty catch

What's the CLI equivalent of the empty catch?

i.e.
try{}
catch
{}

May 21 '07 #1
13 3803
"DaTurk" <mm******@hotmail.comwrote in message
news:11**********************@y2g2000prf.googlegro ups.com...
What's the CLI equivalent of the empty catch?

i.e.
try{}
catch
{}
How about this:

try
{
Console::WriteLine(L"Hello World");
}

catch ( Exception^ )
{
}

Regards,
Will
May 21 '07 #2
try
{
}
catch(...)
{
}

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"DaTurk" wrote:
What's the CLI equivalent of the empty catch?

i.e.
try{}
catch
{}

May 22 '07 #3
DaTurk wrote:
What's the CLI equivalent of the empty catch?

i.e.
try{}
catch
{}
Where is that empty catch allowed? It is not standard C++. Do you mean
catch(...) ?

--
SvenC

May 22 '07 #4
"SvenC" <Sv***@community.nospamwrote in message
news:e4**************@TK2MSFTNGP03.phx.gbl...
DaTurk wrote:
>What's the CLI equivalent of the empty catch?

i.e.
try{}
catch
{}

Where is that empty catch allowed? It is not standard C++. Do you mean
catch(...) ?
It's allowed in C#. It's equivalent to the C++/CLI construct:

try
{
}
catch(Exception^)
{
}

Using catch(...) will also catch native exceptions, and possibly structured
(platform) exceptions, depending on the compiler options used.

-cd
May 22 '07 #5
On May 22, 12:39 am, "SvenC" <S...@community.nospamwrote:
DaTurk wrote:
What's the CLI equivalent of the empty catch?
i.e.
try{}
catch
{}

Where is that empty catch allowed? It is not standard C++. Do you mean
catch(...) ?

--
SvenC
My apologies, I was refering to c#

May 22 '07 #6
Hi Carl!
>>>What's the CLI equivalent of the empty catch?

i.e.
try{}
catch
{}

It's allowed in C#. It's equivalent to the C++/CLI construct:

try
{
}
catch(Exception^)
{
}
No. "catch(Exception^)" is *not* the same as "catch" in C#!

"catch(Exception^)" will *only* catch exceptions which are derived from
"System.Exception"!

"catch" will catch *all* Exceptions (derived from "System.Object")!
It also will catch native exceptins in C#!!!
Therefor the C++/CLI equivalent of "catch" is "catch(System::Object^)" !

See also: Basic Concepts in Using Managed Exceptions
http://msdn2.microsoft.com/en-us/lib...b6(VS.80).aspx
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
May 22 '07 #7
DaTurk schrieb:
What's the CLI equivalent of the empty catch?

i.e.
try{}
catch
{}
try {}
catch(System::Object^)
{}

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
May 22 '07 #8
"Jochen Kalmbach [MVP]" <no********************@holzma.dewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi Carl!
>>>>What's the CLI equivalent of the empty catch?

i.e.
try{}
catch
{}

It's allowed in C#. It's equivalent to the C++/CLI construct:

try
{
}
catch(Exception^)
{
}

No. "catch(Exception^)" is *not* the same as "catch" in C#!

"catch(Exception^)" will *only* catch exceptions which are derived from
"System.Exception"!

"catch" will catch *all* Exceptions (derived from "System.Object")!
It also will catch native exceptins in C#!!!
Egads!

I'd forgotten that the CLR actually supporting throwing something not
derived from System.Exception!

-cd
May 22 '07 #9
It also will catch native exceptins in C#!!!

Wouldn't catch (Exception^) do so as well, giving an SEHException? Or is
that only for p/invoke?
May 22 '07 #10
Hi Ben!
>It also will catch native exceptins in C#!!!

Wouldn't catch (Exception^) do so as well, giving an SEHException? Or is
that only for p/invoke?
SEHException is also derived from "System.Exception". But you can throw
*any* object as an exception. Therefor, if you want to catch *all*
exceptions, you need to catch "System.Object" instead of "System.Exception"!

See:

#pragma unmanaged

void Test1()
{
throw 1;
}

#pragma managed

void Test2()
{
throw 2;
}

void Test3()
{
throw gcnew System::Object();
}

int main()
{
try
{
Test1();
}
catch(System::Object ^o)
{
System::Console::WriteLine("Test1: " + o->GetType()->ToString());
}

try
{
Test2();
}
catch(System::Object ^o)
{
System::Console::WriteLine("Test2: " + o->GetType()->ToString());
}

try
{
Test3();
}
catch(System::Object ^o)
{
System::Console::WriteLine("Test3: " + o->GetType()->ToString());
}
}
Output is:
Test1: System.Runtime.InteropServices.SEHException
Test2: System.Runtime.InteropServices.SEHException
Test3: System.Object

Greetings
Jochen
May 23 '07 #11

"Jochen Kalmbach [MVP]" <no********************@holzma.dewrote in message
news:en**************@TK2MSFTNGP06.phx.gbl...
Hi Ben!
>>It also will catch native exceptins in C#!!!

Wouldn't catch (Exception^) do so as well, giving an SEHException? Or is
that only for p/invoke?

SEHException is also derived from "System.Exception". But you can throw
*any* object as an exception. Therefor, if you want to catch *all*
exceptions, you need to catch "System.Object" instead of
"System.Exception"!

See:
I wasn't doubting that catching System.Object will catch all exceptions...
but wouldn't catching System.Exception also catch all exceptions, decoding
managed objects derived from Exception, and wrapping everything else in
SEHException?
>
#pragma unmanaged

void Test1()
{
throw 1;
}

#pragma managed

void Test2()
{
throw 2;
}

void Test3()
{
throw gcnew System::Object();
}

int main()
{
try
{
Test1();
}
catch(System::Object ^o)
{
System::Console::WriteLine("Test1: " + o->GetType()->ToString());
}

try
{
Test2();
}
catch(System::Object ^o)
{
System::Console::WriteLine("Test2: " + o->GetType()->ToString());
}

try
{
Test3();
}
catch(System::Object ^o)
{
System::Console::WriteLine("Test3: " + o->GetType()->ToString());
}
}
Output is:
Test1: System.Runtime.InteropServices.SEHException
Test2: System.Runtime.InteropServices.SEHException
Test3: System.Object

Greetings
Jochen

May 23 '07 #12
Hi Ben!
I wasn't doubting that catching System.Object will catch all exceptions...
but wouldn't catching System.Exception also catch all exceptions, decoding
managed objects derived from Exception, and wrapping everything else in
SEHException?
I don't understand the background of this question?

I don't know the internals of every assembly; so I don't know if
"System.Exception" will catch *all* exceptions... regardless of
SEHException...

Greetings
Jochen
May 23 '07 #13
>I wasn't doubting that catching System.Object will catch all exceptions...
>but wouldn't catching System.Exception also catch all exceptions, decoding
managed objects derived from Exception, and wrapping everything else in
SEHException?

I don't understand the background of this question?

I don't know the internals of every assembly; so I don't know if
"System.Exception" will catch *all* exceptions... regardless of
SEHException...

You can also use the RuntimeCompatibilityAttribute on your assembly
with WrapNonExceptionThrows = true to make sure all exceptions you see
are derived from Exception (if they aren't already, they get wrapped
in a RuntimeWrappedException). That's what C# does for example.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 23 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, This looks like a long mail, but at the end of this post is my socket wrapper attached. I want to make a timeout procedure that starts counting down after the...
4
by: web1110 | last post by:
I have an array of of 5 string elements. I put values in 3 of them. Yet when I loop over them, I do not catch the empty string. The code output below does not include "Empty" stringx=new...
3
by: scorpion53061 | last post by:
I have little hope of resolving this as I have had to contact outside help. But I thought I would post it here to see if anyone could add an idea or solution. 1. I have a form in a Class...
9
by: John Devlon | last post by:
Hi, I would like to check if a text field is empty; I'm using this code ... Dim strTitle As String = String.Empty Try strTitle = Trim(txtTitle.Text) Catch ex As Exception When strTitle =...
13
by: lithoman | last post by:
I'm stumped here. I run the procedure Batch_Select against the database with @ID=18 and I get the expected data. When it loads into a SqlDataReader, it gets messed up somehow. Initially, after the...
1
by: =?Utf-8?B?RG9u?= | last post by:
Hello, I'm creating a web service that will allow people to enter their contact information into a SQL Server table. I get it to work when I enter all of the fields and press the invoke button,...
1
by: psbasha | last post by:
Hi, Whether we can check the empty list or dict by i"f "conditon or catch this exception by "try" and "catch" blocks. Which will be the best practctice?. In my work I have to play with...
18
by: Dejfson | last post by:
Dear All, can someone clarify me how to return the reference to the empty object in case of error? _not working_ Example of what i'd like to do: const MyClassData& MyClass () {...
3
by: JMcCrillis | last post by:
I've implemented a FileUpload servlet using AJAX and JS. It appears to be working well but for one issue. I used XMLHTTP so I could intercept the response in Javascript and write it out to a field...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.