我有以下代码:
import numpy
def numpysum(n):
a = numpy.arange(n) ** 2
b = numpy.arange(n) ** 3
c = a + b
return c
size = 3000
c = numpysum(size)
Run Code Online (Sandbox Code Playgroud)
运行时,我收到错误:
D:\ Work\programming\python\test_1\src\test1_numpy.py:6:RuntimeWarning:在电源中遇到无效值b = numpy.arange(n)**3
请注意,以下numpyless函数工作正常:
def pythonsum(n):
a = list(range(n))
b = list(range(n))
c = []
for i in range(len(a)):
a[i] = i ** 2
b[i] = i ** 3
c.append(a[i] + b[i])
return c
Run Code Online (Sandbox Code Playgroud)
我想这是因为我尝试将大数字提高到三倍.除了使用浮点数之外,我还能做些什么?
我正在使用Python 3.2.
我在运行时不断收到此错误,我不知道是什么导致它.它认为有文件缺失?
Caused by: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.7.0_07\lib\currency.data
什么是currency.data,可以有人建议为什么会发生这种情况,我的JDK并不是那么老,因为我们现在已经7u17了.
Exception in thread "AWT-EventQueue-0" java.lang.InternalError
at java.util.Currency$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.Currency.<clinit>(Unknown Source)
at java.text.DecimalFormatSymbols.initialize(Unknown Source)
at java.text.DecimalFormatSymbols.<init>(Unknown Source)
at java.text.DecimalFormatSymbols.getInstance(Unknown Source)
at java.text.NumberFormat.getInstance(Unknown Source)
at java.text.NumberFormat.getNumberInstance(Unknown Source)
at java.util.Scanner.useLocale(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at ciphor.CiCompile$7.actionPerformed(CiCompile.java:458)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud) Perl目前$SIG{__DIE__}以这样的方式实现,它将捕获发生的任何错误,即使在eval块内也是如此.这有一个非常有用的属性,您可以在发生错误的确切位置暂停代码,收集实际错误的堆栈跟踪,将其包装在对象中,然后使用此对象作为参数手动调用die.
这种滥用已$SIG{__DIE__}被弃用.据官方统计,你应该更换$SIG{__DIE__}使用*CORE::GLOBAL::die.但是,这两者并不等同.*CORE::GLOBAL::die是不是当发生运行时错误叫!它只是替换显式调用die().
我对更换模具不感兴趣.
我特别感兴趣的是捕获运行时错误.
我需要确保在任何模块中任何深度的任何函数中的任何运行时错误都会导致Perl将控制传递给我,以便我可以收集堆栈跟踪并重新抛出.这需要在eval块内部工作 - 一个或多个封闭的eval块可能想要捕获异常,但运行时错误可能是在任何模块内部没有封闭eval的函数中.
$SIG{__DIE__} 完美支持这一点 - 并忠实地为我服务了几年或更长时间 - 但Be™警告说,这个梦幻般的设施可能会随时被抢走,我不希望有一天会有令人讨厌的惊喜.
理想情况下,对于Perl本身,它们可以$SIG{__RTMERR__}为此目的创建一个新信号(无论如何,切换信号很容易,因为它只挂在一个地方).不幸的是,我的说服力不会导致酗酒者破解瓶子,所以假设不会发生这种情况,那么人们究竟应该如何才能实现干净地捕捉运行时错误的目标呢?
(例如,这里的另一个答案是推荐Carp :: Always,它也挂钩了DIE!)
我正在尝试创建一个用测试用户填充数据库的脚本.我是Django和Python的新手.我继续得到:
Runtime error: App registry isn't ready yet.
Run Code Online (Sandbox Code Playgroud)
这是输出和错误:
starting population script
Traceback (most recent call last):
File "populate.py", line 32, in <module>
populate()
File "populate.py", line 22, in populate
i.save()
File "c:\Python27\lib\site-packages\django-1.7a2-py2.7.egg\django\db\models\base.py", line 603, in save
force_update=force_update, update_fields=update_fields)
...
...
...
File "c:\Python27\lib\site-packages\django-1.7a2-py2.7.egg\django\apps\registry.py", line 156, in get_models
self.check_ready()
File "c:\Python27\lib\site-packages\django-1.7a2-py2.7.egg\django\apps\registry.py", line 119, in check_ready
raise RuntimeError("App registry isn't ready yet.")
RuntimeError: App registry isn't ready yet.
Run Code Online (Sandbox Code Playgroud)
这是代码:
import os
import datetime
def populate():
freer = User.objects.create_user( 'joyyie', 'lolcats@gmail.com', 'e') …Run Code Online (Sandbox Code Playgroud) 这可能是一个奇怪的问题,我似乎无法搜索正确的短语来提取任何相关的答案.
我们有一个在客户端计算机上运行的应用程序并且已缩小.我们生成源映射,但它们不会暴露给生产版本.
我有一个window.onerror,我使用一个捕获所有的草率代码,发现它是我不知道的方式.值得庆幸的是,这几乎从未被利用过.最近,我undefined偶尔会遇到一个错误,所以有人找到了办法做某些不合意的事情.Chrome可以很好地记录堆栈跟踪中的行号和列号,当错误捕获其中一个错误时,我们会记录到日志记录服务器,但是我需要调试并查看min文件并不是很吸引人.而且undefined is not a function是不是非常有帮助要么:)
问题:是否有一个工具 - 可能在nodejs中 - 可以采用min文件,源映射和堆栈跟踪字符串并生成相关文件,行号和列号?
我意识到浏览器在运行时为你做了这个,但是在这种情况下,我没有那么奢侈,因为我试图弄清楚事后的错误究竟是什么.
为什么要0/0投入Overflow errorVBA,而在.Net语言中它只是一个Division by 0错误?
例如,C#它是一个System.DivideByZeroException
static void Main()
{
int k = 0;
int p = 0;
Console.WriteLine(k/p);
}
Run Code Online (Sandbox Code Playgroud)
Div/0错误存在于VBA.但是 0/0给出了溢出异常,而其他除以0的Div/0异常给出了异常:
Public Sub TestMe()
'Integer
PrintAndCheck (11) '- Division by zero error
'Double
PrintAndCheck (0.9) '- Division by zero error
'Long
PrintAndCheck (50000) '- Division by zero error
'String
PrintAndCheck ("1.1") '- Division by zero error
'----------------------------------------------------
'----------------BUT---------------------------------
'----------------------------------------------------
'Integer
PrintAndCheck (0) …Run Code Online (Sandbox Code Playgroud) 我遇到以下错误-> 错误:程序类型已存在:androidx.versionedparcelable.CustomVersionedParcelable
当我单击“生成错误”时,它显示以下内容:
AGPBI: {"kind":"error","text":"Program type already present: androidx.versionedparcelable.CustomVersionedParcelable","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
Run Code Online (Sandbox Code Playgroud)
我不明白是什么原因导致了此问题,因为我正在使用Parcelable库,但从未引起过这种类型的错误。
这是我项目的gradle文件。
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.package.name"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// Lottie
implementation 'com.airbnb.android:lottie:2.8.0'
//Gson
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
//Dagger …Run Code Online (Sandbox Code Playgroud) error-handling android runtime-error gradle android-gradle-plugin
所以我正在编写一个使用蓝牙发现设备的 Android 应用程序。这是我用来开始发现的代码。
try {
myBluetoothAdapter.startDiscovery();
Log.d("Bluetooth Started successfully","yes");
} catch (Error e) {
Log.d("FAILED","Ya failed mate");
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
然后,我注册一个 BroadcastReceiver 以监视何时找到设备。这是我的代码
IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
final ArrayList<String> stringArrayList = new ArrayList<>();
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getApplicationContext(),android.R.layout.simple_list_item_1,stringArrayList);
final ListView listView = findViewById(R.id.listView);
listView.setAdapter(arrayAdapter);
BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d("ACTION RECEIVED","Action was received");
Log.d("Device Name", String.valueOf(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)));
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
stringArrayList.add(device.getName());
arrayAdapter.notifyDataSetChanged();
listView.invalidateViews(); …Run Code Online (Sandbox Code Playgroud) android runtime-error bluetooth broadcastreceiver android-broadcast
我正在 Jupyter 笔记本中运行一个单元,在一段时间(通常是几个小时)后肯定会发生错误。但即使发生此错误后,我也希望编译器继续前进到下一个单元并运行我放入队列中的剩余单元,以便在该单元完成后运行。
我知道异常可能可以做到这一点,但我想知道是否有任何其他特定于 Python 或 Jupyter Notebook 的方法可以做到这一点。
Cell 1: 某些代码运行 # 这里会发生错误并停止执行
单元格 2,3...,n: 某些代码 # 在单元格 1 中发生错误后代码仍应运行
感谢您提供任何解决方案。感谢您的帮助。
是否可以为开发工具设置为source-map的缩小包的webpack生产环境获取可读的堆栈跟踪?我正在运行 Typescript 并与 Webpack 构建做出反应。下面的清单显示了引发异常的示例:
http://localhost:8080/vendors~course-list.3042c44300bc08021f63.bundle.js:2:6029
http://localhost:8080/vendors~course-list.3042c44300bc08021f63.bundle.js:2:5067
in w in b in withRouter(b) in e in e in Suspense in div in e in e in S
Run Code Online (Sandbox Code Playgroud)
在上面的堆栈跟踪中,可以通过将 devtool 选项设置为source-map进行以下观察:
runtime-error ×10
python ×3
android ×2
javascript ×2
bluetooth ×1
django ×1
django-1.7 ×1
excel ×1
excel-vba ×1
gradle ×1
java ×1
numpy ×1
perl ×1
stack-trace ×1
vba ×1