|
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[^]
|
|
|
|
|
In addition to Eddy's comments, I think you are too late in trying to set the parent. You create the process and then sleep for 500, after which you try to set the parent window, which is unlikely to have any effect.
|
|
|
|
|
How to Mark different shapes on Image in asp.net web application using javascript or jquery
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Please, edit your question and provide better information.
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 – ∞)
|
|
|
|
|
One point that OG missed. This is the C# forum, not a JavaScript forum. You might want to look for a more appropriate forum here on CodeProject.
|
|
|
|
|
It was early! I hadn't had enough coffee, clearly...
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 – ∞)
|
|
|
|
|
Start by posting your question in the proper forum; this one is for C#.
|
|
|
|