R
RP
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
anything like ex.number?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
RP said:If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
RP said:If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
Jon Skeet said:For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.
Nicholas Paldino said:Actually, it's not valid C# code. While the CLR does allow for objects
to be thrown, in C#, the compiler requires that the target of the throw
statement derive from System.Exception.
Peter Bromberg said:According to Michaelis, "In C# 2.0, all exceptions, whether deriving from
System.Exception or not, will propagate into C# assemblies as derived from
System.Exception. .... the CIL code corresponding to an empty catch block
is,
in fact, a catch(object) block..."
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
Nicholas Paldino said:Actually, it's not valid C# code. While the CLR does allow for
objects
to be thrown, in C#, the compiler requires that the target of the throw
statement derive from System.Exception.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Chris Mullins said:If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.
heh. Perfectly valid, if not quite correct, code...
Object errorNumber = (object) 101;
throw errorNumber;
One day I'm going to figure out why any arbitrary thing can be thrown,
rather than constraining it to only Exceptions...
Nicholas Paldino said:Which is correct, but it doesn't validate Chris's post, which indicates
that you can actually throw something in C# which does not derive from
Exception.
You could do this in C++/CLI or in IL, but not in C#. And yes, you can
catch it with the catch block which doesn't have an exception argument.
I actually did some of the review work on that book, and know Mark, so I
know exactly which section you are referring to. =)
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Peter Bromberg said:According to Michaelis, "In C# 2.0, all exceptions, whether deriving from
System.Exception or not, will propagate into C# assemblies as derived from
System.Exception. .... the CIL code corresponding to an empty catch block
is,
in fact, a catch(object) block..."
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
Nicholas Paldino said:Actually, it's not valid C# code. While the CLR does allow for
objects
to be thrown, in C#, the compiler requires that the target of the throw
statement derive from System.Exception.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
For many exceptions there *isn't* an error number - after all, you can
create whatever exception you want and throw it.
heh. Perfectly valid, if not quite correct, code...
Object errorNumber = (object) 101;
throw errorNumber;
One day I'm going to figure out why any arbitrary thing can be thrown,
rather than constraining it to only Exceptions...
Nicholas Paldino said:Actually, it's not valid C# code. While the CLR does allow for objects
to be thrown, in C#, the compiler requires that the target of the throw
statement derive from System.Exception.
RP said:If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
RP said:If an exception occurs, how to get the error number. I mean, is there
anything like ex.number?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.