|
Eddy Vluggen wrote: Write one.
Well I could, but I like to run the debugger with first chance exceptions being thrown, its a really powerful tool to track things that fail. Yes, I can ignore that particular exception but I'd rather not. The answers as it turns out is to use the socket class which isn't so fascist.
Regards,
Rob Philpott.
|
|
|
|
|
Add an attribute to that single method;
[DebuggerStepThrough]
static bool TryFail()
{
try
{
throw new NotImplementedException();
}
catch (NotImplementedException)
{
Debug.WriteLine("Caught expected NotImplementedException");
return false;
}
return true;
}
Rob Philpott wrote: Yes, I can ignore that particular exception but I'd rather not. Did you mean "ignore each instance of that exception", or "that particular catch in that specific method"?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
OriginalGriff wrote: I really can't decide whether to vote you up for that comment An unhelpful remark is not worth the upvote.
OriginalGriff wrote: or down for introducing the concept of "On Error Resume Next" to c#... Now that you mention it, there's an "abuse" button
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Oh, that crossed my mind as well!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
We actually have a function that looks almost exactly like this in our code base. The difference is that it's called once for a user interaction, at the top level, and in the catch is some code that makes and displays an error UI.
'Log and carry on' is bad. 'Log, inform and don't crash the host application' is good
|
|
|
|
|
Do not use exceptions to control flow of your code. Think of exceptions like "something bad happened and I don't know what to do NOW". The only valid reason to throw the exception is that current method is not able to recover from failure.
Failed validation of arguments is not a reason to throw the exception - just check the result and execute the rest of your code or not.
And yes, don't use GC.Collect() - forget the garbage collector exists and let it do its job.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
deflinek wrote: Failed validation of arguments is not a reason to throw the exception
Um. ArgumentException class[^]
"ArgumentException is thrown when a method is invoked and at least one of the passed arguments does not meet the parameter specification of the called method."
So yes, it is: if the argument must be between 0 and 100 and the actual argument is -42, then that's an ArgumentException candidate.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I'm sorry, I wasn't clear enough You are absolutely right that if method expects certain format for arguments to do its job should throw an exception if they are not valid.
In my post I was refering to OP's code when he calls validation method, then check for result and throws exception for certain values but catches it later in the same method. and continue processing. This is pure evil in my opinion
My point was - throw an exception only if you can't handle the situation inside the method and only if it's... exceptional situation. Do not use exception to control the flow.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
I can agree with that - Exceptions are for problems, not an advanced form of return code...
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Been there, done that
As everyone else mentions do not use try blocks to catch exceptions in order to keep your application alive.
An exception is just that - something that is unexpected, so you need to rework your code so you actually deal with the conditions that lead to that exception.
While you have those try blocks in your code you won't know how many bugs your code has.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hi everyone,
I am using below codes to get information from HardDisk.
ManagementObjectSearcher HardwareQuerySearcher = null;
HardwareQuerySearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject hard in HardwareQuerySearcher.Get())
{
Hard hdd = new Hard();
hdd.Model = hard["Model"].ToString();
hdd.Type = hard["InterfaceType"].ToString();
hdd.Type = hard["SerialNumber"].ToString();
}
Do you know how to list/or show all fields/properties that existing in this query ?
For example: I am want to know wherether the field "SerialNumber" existing or not ?
Thanks and regards,
Tai
|
|
|
|
|
have a read of this Win32_DiskDrive class[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
|
MSDN[^] is your friend.
Everyone dies - but not everyone lives
|
|
|
|
|
Thank you.
Do you know what is difference between the property: SerialNumber of "Win32_PhysicalMedia" and SerialNumber of "Win32_DiskDrive" ?
When I use Win32_DiskDrive, I can't get SerialNumber on Win XP
Regards,
Tai
|
|
|
|
|
As the Win32_DiskDrive document states, this property is not available on XP
Quote: SerialNumber
Data type: string
Access type: Read-only
Number allocated by the manufacturer to identify the physical media.
Example: WD-WM3493798728
Windows Server 2003 and Windows XP: This property is not available.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Yes, do you know what is the property that I can get an unique value for computers that using win xp ?
Thanks and regards,
Tai
|
|
|
|
|
protected void btnAdd_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
if (!dt.Columns.Contains("Sno"))
{
dt.Columns.Add("Sno");
}
if (!dt.Columns.Contains("ItemName"))
{
dt.Columns.Add("ItemName");
}
if (!dt.Columns.Contains("ItemQuantity"))
{
dt.Columns.Add("Quantity");
}
if (!dt.Columns.Contains("Price"))
{
dt.Columns.Add("Price");
}
if (!dt.Columns.Contains("Total"))
{
dt.Columns.Add("Total");
}
if (Session["datatable"] != null)
{
dt = (DataTable)Session["datatable"];
}
DataRow dr = dt.NewRow();
dr[0] = txtSno.Text;
dr[1] = cmbItems.Text;
dr[2] = txtQuantity.Text;
dr[3] = txtPrice.Text;
}
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
namespace putty
{
public partial class Form1 : Form
{
public int tabp = 0;
public Panel panel;
public string select;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
string[] files = Directory.GetFiles("connections\\", "*.bat");
listBox1.Items.AddRange(files);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
txtbatch.Clear();
txtbatch.Text += "C:/plink.exe -v -ssh " + txtusr.Text + "@" + txtip.Text + " -pw " + txtpass.Text;
File.WriteAllText(@"connections\\" +txtname.Text+".bat", txtbatch.Text);
MessageBox.Show("Please Refresh");
}
public void button1_Click(object sender, EventArgs e)
{
TabPage page = new TabPage();
Panel panel= new Panel();
panel.Dock = DockStyle.Fill;
tabControl1.TabPages.Add(page);
tabControl1.SelectedTab = page;
cmd(panel);
}
public void cmd(Panel panel)
{
select = listBox1.Text;
const int WM_SYSCOMMAND = 0x112;
const int SC_MINIMIZE = 0xF020;
const int SC_MAXIMIZE = 0xF030;
Process p = Process.Start(
new ProcessStartInfo()
{
FileName = select,
WindowStyle = ProcessWindowStyle.Minimized
});
Thread.Sleep(500);
IntPtr value = SetParent(p.MainWindowHandle, panel.Handle);
SendMessage(p.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
}
}
modified 1-Apr-14 6:59am.
|
|
|
|
|
Send the panel to the command method:
cmd(panel);
...
public void cmd(Panel panel)
|
|
|
|
|
Hi,
i've edited my original post to show you how it is now, i think thats is working however its not calling the command prompt window into the panel now its opening cmd separately from the application ??
|
|
|
|
|
Could you please add <pre> tags around your code so it is properly formatted?
antrock101 wrote: now its opening cmd separately from the application No idea why that may be happening; you need to do some debugging to gather more details.
|
|
|
|
|
Hi, i've added the code tags in as asked.
|
|
|
|
|
Look at it again I think its not calling it in the panel because it doesn't know what the panel.handle is
IntPtr value = SetParent(p.MainWindowHandle, panel.Handle);
but im not sure how to amend it
|
|
|
|
|
antrock101 wrote: Look at it again I think its not calling it in the panel because it doesn't know what the panel.handle is That's guessing, not thinking.
You forgot to add the panel to the tabpage. It's not on the form. Also looks a bit weird, trying to get a console-window in a Panel - why not redirect its output?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|