473,403 Members | 2,323 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,403 software developers and data experts.

Making your own exception?

Throw new Excption ("bla, bla, bla")
....
Catch E as Exception
If E.Message.Equals("bla, bla, bla") Then ...
Mostly i just use the standard "Exception"-object whenever i throw an
exception, but it would be nice sometimes to make you own
"MyException"-object that you
can then easier Catch. using:

Catch Exp as MyException
....

Whenever i use the standard exception-object i check to see if the E.Message
equals the one i made, but since this isn't a very good way of coding, so
how do i make my own Exception-object. Do i need to make a new class that
inherits/implements from the Exception.class, or is there a way to do it
without starting making a exception-class for each object you want a
specialized exception for. Someting you do when you trow the exception for
example?

Nov 20 '05 #1
3 3171
"Jarod_24" <ja******@hotmail.com> schrieb
Throw new Excption ("bla, bla, bla")
...
Catch E as Exception
If E.Message.Equals("bla, bla, bla") Then ...
Mostly i just use the standard "Exception"-object whenever i throw
an exception, but it would be nice sometimes to make you own
"MyException"-object that you
can then easier Catch. using:

Catch Exp as MyException
...

Whenever i use the standard exception-object i check to see if the
E.Message equals the one i made, but since this isn't a very good way
of coding, so how do i make my own Exception-object. Do i need to
make a new class that inherits/implements from the Exception.class,
or is there a way to do it without starting making a exception-class
for each object you want a specialized exception for. Someting you do
when you trow the exception for example?


Has been discussed here in the past days. See subject "Error handling -
custom 'throw?'"
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
* "Jarod_24" <ja******@hotmail.com> scripsit:
Throw new Excption ("bla, bla, bla")
...
Catch E as Exception
If E.Message.Equals("bla, bla, bla") Then ...
Mostly i just use the standard "Exception"-object whenever i throw an
exception, but it would be nice sometimes to make you own
"MyException"-object that you
can then easier Catch. using:

Catch Exp as MyException
...

Whenever i use the standard exception-object i check to see if the E.Message
equals the one i made, but since this isn't a very good way of coding, so
how do i make my own Exception-object. Do i need to make a new class that
inherits/implements from the Exception.class, or is there a way to do it
without starting making a exception-class for each object you want a
specialized exception for. Someting you do when you trow the exception for
example?


This depends on various aspects:

* If there is already an appropriate exception class defined in the
.NET Framework, I would use this class instead of creating a new
class.

* If there is no class available in the .NET Framework, I would create
a custom exception class in order to make it easier to handle the
exceptions of a certain type.

Notice that it doesn't make sense to create a new exception class for
each exception -- sometimes it's better to use the same exception class,
for example, 'IOException'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Jarod,
In addition to the other comments.

These are the guidelines that I try to follow:

http://msdn.microsoft.com/library/de...Guidelines.asp

The following article provides a good template for defining well-tempered
exceptions:

http://msdn.microsoft.com/library/de...rp08162001.asp

Although the code is in C# it should be easily converted to VB.NET.
Catch E as Exception
If E.Message.Equals("bla, bla, bla") Then ... Did you know you can use a When clause here?

Try
Catch ex As Exception When ex.Message.Equals("bla, bla, bla")
Catch ex As Exception When ex.Message.Equals("alb, alb, alb")
End Try

Hope this helps
Jay

"Jarod_24" <ja******@hotmail.com> wrote in message
news:5d******************************@news.teranew s.com... Throw new Excption ("bla, bla, bla")
...
Catch E as Exception
If E.Message.Equals("bla, bla, bla") Then ...
Mostly i just use the standard "Exception"-object whenever i throw an
exception, but it would be nice sometimes to make you own
"MyException"-object that you
can then easier Catch. using:

Catch Exp as MyException
...

Whenever i use the standard exception-object i check to see if the E.Message equals the one i made, but since this isn't a very good way of coding, so
how do i make my own Exception-object. Do i need to make a new class that
inherits/implements from the Exception.class, or is there a way to do it
without starting making a exception-class for each object you want a
specialized exception for. Someting you do when you trow the exception for
example?

Nov 20 '05 #4

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

Similar topics

0
by: Mark | last post by:
I'm betting it me. Here is the simple schema I'm using: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"...
5
by: Nick Keighley | last post by:
Hi, In the beginning the code was:- BRUSHH new_brush = create_brush() BRUSHH old_brush = select_brush (new_brush) draw(...) select_brush (old_brush) destroy_brush (new_brush)
1
by: Jarod_24 | last post by:
Throw new Excption ("bla, bla, bla") .... Catch E as Exception If E.Message.Equals("bla, bla, bla") Then ... Mostly i just use the standard "Exception"-object whenever i throw an exception,...
1
by: Chris Langston | last post by:
We are seeing a very frustrating intermittent problem. We are making Synchronious web service method calls from a .NET windows Service using the following syntax WebRequest.getResponse call it...
37
by: yogpjosh | last post by:
Hello All, I was asked a question in an interview.. Its related to dynamically allocated and deallocated memory. eg. //start char * p = new char; ...
18
by: dbahooker | last post by:
team i'm having a tough time getting these data readers to work correctly I'd just like to be able to centralize my GetDataReader functions; so i can pass a simple SQL statement and be passed...
14
by: Ben Voigt | last post by:
Under certain circumstances I get: First-chance exception at 0x7c812a5b (kernel32.dll) in LTMGUI.exe: 0xC0020001: The string binding is invalid. First-chance exception at 0x7c812a5b (kernel32.dll)...
12
by: Premal | last post by:
Hi, I tried to make delete operator private for my class. Strangely it is giving me error if I compile that code in VC++.NET. But it compiles successfully on VC++6.o. Can anybody give me inputs...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.