C#异常处理

flyingyinjun 2010-01-10 08:51:24
我是一个初学者,我想问一下,下面的程序运行结果是不是这样???
结果:
divided error!!!
programm end!!!
all main programm end!!!




程序:
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x, y;
x=3;y=0;
morecatchmethod(x,y);
console.writeline("all main programm end!!!");
}
static void morecatchmethod(int x, int y)
{
int z;
try
{
z=(int)x / y;
Console.WriteLine("{0}", z);
}
catch (DivideByZeroException ex)
{
Console.WriteLine("divided error!!!");
}
Console.WriteLine("programme end!!!");
}
}
}
...全文
73 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenmaolong034 2010-01-10
  • 打赏
  • 举报
回复
对 就是这样 你 运行
ch46485f 2010-01-10
  • 打赏
  • 举报
回复
对 是那样运行的!
段传涛 2010-01-10
  • 打赏
  • 举报
回复
static void morecatchmethod(int x, int y)
{
int z;
try
{
z=(int)x / y;
Console.WriteLine("{0}", z);
}
catch (DivideByZeroException ex)
{
Console.WriteLine("divided error!!!");
}
Console.WriteLine("programme end!!!");
//这里加个 catch吧 不然 你的try 没有意义了
catch(错误信息)
{提示}
}
leafold 2010-01-10
  • 打赏
  • 举报
回复
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x, y;
x=3;y=0; //y=0
morecatchmethod(x,y);//调用y
console.writeline("all main programm end!!!");
}
static void morecatchmethod(int x, int y)
{
int z;
try
{
z=(int)x / y;//y=0,被0除错
Console.WriteLine("{0}", z);
}
catch (DivideByZeroException ex)
{
Console.WriteLine("divided error!!!");
}
Console.WriteLine("programme end!!!");
}
}
}
kensouterry 2010-01-10
  • 打赏
  • 举报
回复
对 没有错!是那样运行的!
bcl258586301 2010-01-10
  • 打赏
  • 举报
回复
应该木问题的,你可以运行下试试..

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧