from __future__ import division # if using python 2
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(1e30, 1e33, 1001)
y = x**(-1/3)*(1.102*10**20)*(1-(x**(4/3)*2.424*10**(-45)))**(1/2)
plt.plot(x,y)
plt.xlabel("M(g)", fontsize =13)
plt.ylabel("R(cm)", fontsize=13)
plt.show()
在运行上面的代码时,两个控件都没有进入var http = require('http');
var url = require('url');
var server = http.createServer(function(request, response) {
http.get('http://nodejs.org/dist/index.json', (res) => {
response.write("Inside http");
response.end();
}).on('error', function(e) {
console.log(e);
});
});
server.listen(3000);
内部,也没有引发任何错误。我在这里错过了捕获错误的内容吗?
注意:服务器创建于3000
答案 0 :(得分:1)
在您的应用中添加应用级错误处理程序。如果出现任何问题,它将捕获错误
process.on('uncaughtException', function (err) {
// This should not happen
logger.error("Pheew ....! Something unexpected happened. This should be handled more gracefully. I am sorry. The culprit is: ", err);
});
答案 1 :(得分:1)
似乎应该按照以下方式放置http.get以使其正常工作:
var http = require('http');
console.log('Before server');
var server = http.createServer(function(request, response) {
console.log('Request received');
});
server.listen(3000, function() {
http.get('http://nodejs.org/dist/index.json', (res) => {
console.log('Inside http');
})
.on('error', (e) => {
console.error(`Got error: ${e.message}`);
});
});