我正在尝试处理应用程序中主线程上未捕获的异常,因此我可以将它们记录到文件中(我的应用程序是命令行应用程序,可以在通宵工作中运行,因此如果出现问题,我希望管理员能够轻松查看例外)。我已将其简化为一个尽可能简单的测试用例。
生成的Maven应用(根据入门文档):
mvn -B archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.mycompany.app \
-DartifactId=my-app
Run Code Online (Sandbox Code Playgroud)
App.java:
package com.mycompany.app;
public class App {
public static void main(String[] args) throws Exception {
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
System.out.println("Handled exception - let's log it!");
// Logging code here
}
});
System.out.println("Exception testing");
throw new Exception("Catch and log me!");
}
}
Run Code Online (Sandbox Code Playgroud)
与mvn exec:java
产生一起运行:
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 VSCode 的调试器调试 Next.JS 应用程序的服务器端代码,但我无法获取任何要绑定的断点。使用 chrome 的开发工具(通过 chrome://inspect)进行调试以附加到调试器,其行为符合预期。
重现步骤:
npx create-next-app@latest nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter"
(按照https://nextjs.org/learn/basics/create-nextjs-app/setup中的说明)生成 Next.JS 应用程序。launch.json
中所述创建Next.js: debug server-side
在 VSCode 中运行调试任务pages/index.js
(我在组件内的return语句上设置了我的断点Home
)。预期行为:
实际行为:
附加信息:我尝试在launch.json
. 手动运行后启动它npm run dev
给了我更多信息 - VSCode 给出了有关正在发生的事情的更多提示 - 请参阅屏幕截图 2 和 3。这是附加条目:
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"type": "node"
}
Run Code Online (Sandbox Code Playgroud)
我错过了某些步骤吗?好像源映射无法正常工作或其他什么?
系统信息