Nov 22 2011, 05:31 AM
M. Bison Wrote:Why don't you simply think ahead and prevent the overflows and errors from ever having occurred to begin with?I do, but i use this Method to keep my program from crashing, in case i forgot something, or if there was a missing link or file (It's very useful).
I'll give you an example:
this is a simple calculator code free of errors or overflows, before running..
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace hhhhh
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
int z;
char t = Convert.ToChar(textBox2.Text);
switch (t)
{
case '+':
z = Convert.ToInt32(textBox1.Text != null) + Convert.ToInt32(textBox3.Text != null);
textBox4.Text = z.ToString();
break;
case '-':
z = Convert.ToInt32(textBox1.Text) - Convert.ToInt32(textBox3.Text);
textBox4.Text = z.ToString();
break;
case '*':
z = Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox3.Text);
textBox4.Text = z.ToString();
break;
case '/':
float doc = Convert.ToSingle(textBox1.Text) / Convert.ToSingle(textBox3.Text);
textBox4.Text = doc.ToString();
break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("NeptuneHACK!");
}
}
}
& keeps me from being embarrassed in front of the Prof when i show her the Project. ^_^