简体   繁体   中英

An unhandled exception occurred during the execution

I have handling the exception in my code as below, but still get error:

    catch (Exception e)
    {
       throw new Exception(e.Message);
    }

And here is the error:

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Object reference not set to an instance of an object.

It sounds more like you are accessing a object that has been released/ or a null object.

IN the Catch block instead you use the following code to display an exception u r again throwing the Exception, remove it and try again. Hope it helps.

You still get an error because you are throwing a new exception in the catch block.

From a catch block you are throwing a new excpetion which is creating a problem try to remove throw new exception or add a new parent try catch block

If you are handling your exception in this way (only retrowing it) than don't catch exeptions on this level. Catch Exceptions in the method that's calling this function (Or where you want to handle your exception) and do your handling/showing the message overthere.

You probably don't have another try/catch block in the calling method which is causing the unhandled exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM