|
HI all,i had a query regarding Exception Handling.consider there r 30 webpages,which doesnt consists any type of Exception Handling techniques or code.as it is maintenance and enhancement project,how can i trace the errors and how to make it follow coding standards.
pls help me.
Thanks in advance
Bobby
|
|
|
|
|
A good first step would be to write a base page class, which handles and logs unhandled exceptions, and make all pages derive from it. From there, you need to decide where exception handling is needed for specific cases, and add it.
Putting all code in try/catch(Exception) blocks is bad practice, you should add exception handling only for specific exceptions that you can anticipate and recover from.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
HI Graus
Thanks for ur fast reply.can u tell me some more detail how it handles and logs the exceptions.
pls spare me some little time
thanq
|
|
|
|
|
Any code I write, at the top level, will just catch it, write it out to a log file ( the exception and the stack trace ), and then show an error ( if it's winforms ) and gracefully exit. But, that's the last stop, the place where stuff I don't want to happen, gets recorded so I can have some lead on how to never let it happen again.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
try
{
// some code
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
VirtualVoid.NET
|
|
|
|
|
If user RegisterWindowMessage()in app A, than send this message, how to set hook to capture this message in app B?
|
|
|
|
|
A window can capture all messages it gets by overriding WndProc
for examples, just search "WndProc" on CodeProject.
Luc Pattyn
|
|
|
|
|
But in A app, there is no form, that means i can't override WndProc or DefWndProc,so what can i do?
thanks
|
|
|
|
|
This may be a good reason to give your app a window, possibly an invisible one !
Luc Pattyn
|
|
|
|
|
At the beginning, i want to use a invisible window,but i think it is a little uglily, so i passed this idea, At present most probably, this is a convenient and rapid way to solve the problem.
|
|
|
|
|
I am pretty sure it is the only way if you want to receive Windows Messages,
as was clear from your initial post. Many apps have a window just to be able to receive
such messages.
Luc Pattyn
|
|
|
|
|
OK, i will try!
thank you very much Luc!
|
|
|
|
|
Hello,
I am trying to render a graphical sort of output in a console application.The result is word wrapping on the console.So i want to enable horizontal scrolling for the console window.How do i do it?
rgds,
chax
chax
|
|
|
|
|
In the console you can set "BufferWidth", i.e. the size of the console buffer, to some other value than the default 80, and you will get horizontal scrolling.
Internet - the worlds biggest dictionary
|
|
|
|
|
hello all,
am making a project that has a datagridview that will be filed from a SQL DB,
1) there si a field in the DB that has a data in hexadecimal format, so how i can fill it after converting it to string.
2) what is the process of allowing the user to add, delete and update on the datagridview directly??
sorry for the ones who see that i ask an easy questions but they are not easy 4 all of ones as u see :->
Thanks alot
Hamody
|
|
|
|
|
hi,
when u write the query to retrieve the data, convert the hexadecimal value to a string so that ur table will not have any column with hexadecimal values.
you can use edit, update, cancel and do the required manipulations on the datagrid, write the required logic in few methods and assign these methods accordingly to the datagrid events!!!
Gautham
|
|
|
|
|
thanks, but how i can convert from hexadecimal to string, io dont know the function to do this.
have u an example on add, delete, update on the datagridview
Thanks alot
Hamody
|
|
|
|
|
Hi,
int.Parse(myString, NumberStyles.AllowHexSpecifier);
will do it; I find the style name confusing, it means read-as-hex but does not
allow the 0x specifier !
Luc Pattyn
|
|
|
|
|
i tried it as:
string hhhh;
hhhh=int.Parse("ffff", NumberStyles.AllowHexSpecifier).ToString();
MessageBox.Show(hhhh);
use using System.Globalization; as name space
but it hasnt convert the hex to string
what can i do ???
Thanks alot
Hamody
|
|
|
|
|
Your code seems right.
This code snippet works for me:
public override void Run(int arg) {
hex("12");
hex("1234");
hex("1aBd");
hex("FFFF");
hex("ffff");
}
public void hex(string s) {
int i=int.Parse(s,NumberStyles.AllowHexSpecifier);
log("hex "+s+" = decimal "+i);
}
It produces
hex 12 = decimal 18
hex 1234 = decimal 4660
hex 1aBd = decimal 6845
hex FFFF = decimal 65535
hex ffff = decimal 65535
so I expect your problem is elsewhere.
Luc Pattyn
|
|
|
|
|
datagrid examples:http://www.4guysfromrolla.com/webtech/122300-1.shtml
give me a detailed explaination reg the hexadecimal prblm....
Gautham
|
|
|
|
|
ok thanks first,,,
i mean that i have SQL database table which has a field containg hexadecimal data (arabic converted to hexadecimal) i want 2 show converted data on the datagridview
Thanks alot
Hamody
|
|
|
|
|
Check this link: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1161100&SiteID=1
Gautham
|
|
|
|
|
G'day!
I'm currently writing a program that imports and uses functions from an unmanaged DLL. One of these functions expect as a parameter a struct containing some data (whose types I have previously passed successfully to other functions in the same dll) and an array of a struct containing an LPVOID type and a function pointer(which I have sucessfully passed). I don't understand how marshalling this type should work, if anyone could enlighten me, I'd be most thankful. Heres my current implementation:
<br />
[StructLayout(LayoutKind.Sequential,Pack = 0)]<br />
public struct StructA<br />
{<br />
public StructB[] sBArray;<br />
}<br />
<br />
[StructLayout(LayoutKind.Sequential,Pack = 0)]<br />
public struct StructB<br />
{<br />
[MarshalAs(UnmanagedType.FunctionPtr)]<br />
public aDelegate delegateMember;<br />
public object TheProblemChild;
}<br />
<br />
public class Bleh<br />
{<br />
[DllImport("Unmanaged.dll", EntryPoint = "UnmanagedImport")]<br />
private static extern int UnmanagedImport([MarshalAs(UnmanagedType.Struct)] StructA sA);<br />
public int CallUnmanagedFunc()<br />
{<br />
StructA sA = new StructA();<br />
SA.sBArray = new StructB[7];<br />
<br />
<br />
return UnmanagedImport(sA);
}<br />
The indicated position throws an ArgumentException seemingly no matter what I try. The message is "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" and the stacktrace points directly to the imported function. In short (;P), I ask: How can I pass, from managed code to unmanaged, a parameter expected to be of type LPVOID?
Sorry if I overwhelmed you, or maybe turned non understandable.
|
|
|
|
|