错误是Corrent上下文中不存在Err [英] Error is Err is does not exist in Corrent Context

查看:79
本文介绍了错误是Corrent上下文中不存在Err的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助..... !!


Pls Help.....!!


public static void SaveJPGWithCompressionSetting(System.Drawing.Image image, string szFileName, long lCompression)
    {
        // ERROR: Not supported in C#: OnErrorStatement
        //goto chkErr;
        //goto chkErr onError;
        bool errOcr = false;
        if (errOcr == true)
        {
            goto chkErr;
        }
        EncoderParameters eps = new EncoderParameters(1);
        eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, lCompression);
        ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
        image.Save(szFileName, ici, eps);
        return;
    chkErr:
        string strPageErro="Error: " +Err.Number + " " +Err.Description + "\\r\\n" + "Choose a different name for file.";
        //mbox("Error: " +Err.Number + " " +Err.Description + "\\r\\n" + "Choose a different name for file.");
        errOcr = true;
        //Resume next;

    }




谢谢... !!




Thanks...!!

推荐答案

narendrarathod写道:
narendrarathod wrote:

错误:不支持在C#中:OnErrorStatement

ERROR: Not supported in C#: OnErrorStatement



哪一部分让您感到困惑?




Which part of that is confusing you ?


narendrarathod写道:
narendrarathod wrote:

bool errOcr = false;
如果(errOcr == true)
{
goto chkErr;
}

bool errOcr = false;
if (errOcr == true)
{
goto chkErr;
}



这显然是白痴.删除它,它什么都不做,并且是一个设计不良的构造.请改用try catch.在我看来,这就像是不良的VB6,有人将其转换为VB.NET,而您正尝试手动转换为C#.是吗?



This is obviously idiocy. Delete it, it does nothing, and is a poorly designed construct. Use a try catch instead. This looks to me like bad VB6 that someone converted to VB.NET and you''re trying to move to C# by hand. Is that right ?


我同意Christian的观点,这看起来像是转换后的VB6代码.

这是东西:

在VB.NET中,"Err"对象仍然存在,但在C#中却不存在.

您需要做的就像克里斯蒂安建议的那样:将代码包装在try/catch语句中:

I agree with Christian, this looks like converted VB6 code.

Here''s the thing:

The "Err" object still exists in VB.NET, but it DOESN''T exist in C#.

What you need to do is like Christian suggested: Wrap your code in a try/catch statement:

try
{
//Your code goes here
}
catch (Exception ex)
{
//Error caught here, now use the properties of the Exception object, e.g. Discription:
string errorDiscription = ex.Discription;
}



祝你好运

另一件事:即使在.NET中是可能的;我想不出您需要使用"Goto"的任何原因,因此请避免在以后再使用...只是更好编程的提示



Good luck

Another thing: Even though it is possible in .NET; I can''t think of ANY reason where you would need to use "Goto", so try to avoid that in the future... Just a tip for better programming


你的问题吗?您所做的就是发布一些代码.我们不能只是凭空想出你想要的东西.
So, what''s your question? All you did was post some code. We can''t just divine from thin air what you might want.


这篇关于错误是Corrent上下文中不存在Err的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆