我习惯用Java思考,而我正试图绕过node.js. 我的程序需要在出现问题时记录信息,我发现我必须在我的node.js程序中输入大量的样板代码才能获得我在Java中免费获得的内容.
我的问题归结为:
这是一个点头的Java程序,它尝试(并且失败)连接到Mongo数据库:import java.net.UnknownHostException;
import com.mongodb.Mongo;
public class Test {
public static void main(final String[] args) throws UnknownHostException {
final Mongo mongo = a();
}
private static Mongo a() throws UnknownHostException {
return b();
}
private static Mongo b() throws UnknownHostException {
return c();
}
private static Mongo c() throws UnknownHostException {
return new Mongo("non-existent host");
}
}
Run Code Online (Sandbox Code Playgroud)
...这给出了有用的堆栈输出:
Exception in thread "main" java.net.UnknownHostException: non-existent host
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud)