trullock / NUglify

NUglify is a HTML, JavaScript and CSS minification Library for .NET (fork of AjaxMin + new features)
Other
396 stars 79 forks source link

Execute the formatting code, but the error cannot be caught using try catch #361

Open colindcli opened 1 year ago

colindcli commented 1 year ago

The code.zip compressed package contains a js test file. When using the above code var setting = CodeSettings.Pretty(); Uglify.Js(code, setting); to format js, an error is reported. The error message is $exception {"Exception_WasThrown"} System.StackOverflowException I use try catch, but the error cannot be caught, and the program crashes directly.

code.zip

try{
    var setting = CodeSettings.Pretty(); 
    //Use the js file in the code.zip compressed package 
    Uglify.Js(code, setting);
} catch(Exception e){
    //but can't catch the error
}

The main problem is that the catch cannot catch the error

Originally posted by @colindcli in #355 (comment)

code.zip

code.zip contains a js file, because the file is too large, please decompress it locally.

// read js file code
var code = System.IO.File.ReadAllText("code.js");

try
{
    var setting = CodeSettings.Pretty();
    Uglify.Js(code, setting);
}
catch (Exception e)
{
    //but can't catch the error
}

Executing formatting will report an error. It doesn’t matter if the error is reported, but the error cannot be caught

colindcli commented 1 year ago

Don't rush to close it if it can't be solved