Can we override global message exception ?

phicha

Well-known member
Joined
May 11, 2009
Messages
45
Programming Experience
Beginner
i mean, can we global change default message error on system.exception

some how if we catch exception on try
ussually i put messagebox.show(ex.message)

and it show primary key error,
and i want to change this primary key error to my own message like "data already in database"

but i dont want to put or change all my source code, since it will need a lot of times since there is many catch.

thanks,
 
thanks sir,
there is many procedure for save on each form.

i put this code on each form
VB.NET:
Try
    ' Save Code goes here.


Catch ex As SqlException
if ex.number=2627 then
    messagebox.show("data already in database")
else
    messagebox.show(ex.message)
end if
Catch ex As Exception
    messagebox.show(ex.message)
End Try

it seem make a little mess on my code since it doesnt seem enough good, since it need me to repeat it on each form.

is there others simple way or more effective way to use try catch ?
and where can i learn a best practice and effective code ?

thanks for any help,
 
Typically when you need to reuse code between different classes you put that code in a separate class. Now each consumer can create its own instance with New keyword and call its members. If those members doesn't depend on a specific instance of the class they can and should be declared Shared, and can then be accessed directly without creating the instance.

Here is an example of a class with one instance member and one shared member:
VB.NET:
Class Sample
   Public Sub InstanceMethod()
   Public Shared Sub SharedMethod()
End Class
The consumer can create an instance locally:
VB.NET:
Dim s As New Sample
or at module level:
VB.NET:
Private s As New Sample
then call the instance member:
VB.NET:
s.InstanceMethod()
Without creating an instance the consumer can call the shared member directly:
VB.NET:
Sample.SharedMethod()
I recommend that you pick up a book to learn all the basics of VB.Net sooner than later.
 
Thanks sir,
i already have some book and already learn it.
and what u teach before. i learned it already too.

but somehow , i think i am still not good to make a architecture design and best pratice on implement new command technology like linq and etc on my program.

thanks,
 
Back
Top