当我运行下面的代码时,抛出OutOfMemoryError,但是没有被捕获,尽管有一些条款应该捕获它:
public class SomeClass {
public static void main(String[] args) {
try {
//Allocate a huge amount of memory here
} catch (OutOfMemoryError oome) {
System.out.println("OutOfMemoryError=<" + oome + ">");
} catch (Error err) {
System.out.println("Error=<" + err + ">");
} catch (Throwable t) {
System.out.println("Throwable=<" + t + ">");
} finally {
System.out.println("'Finally' clause triggered");
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出如下:
'Finally' clause triggered
Exception in thread "main"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
Run Code Online (Sandbox Code Playgroud)
没有抓住异常这一事实对我来说毫无意义.该的OutOfMemoryError文档确认异常应该由任何Throwable的,错误或OutOfMemoryError异常捕获.(请注意,"java.lang."说明符不会影响行为.)
我在StackOverflow上看到的所有其他问题都是"为什么我的OutOfMemoryError异常没有被捕获?" …
我想使用PowerShell在特定配置单元中查找包含字符串的所有注册表项和值,这些字符串foo可能嵌入在更长的字符串中。查找密钥并不难:
Get-ChildItem -path hkcu:\ -recurse -ErrorAction SilentlyContinue | Where-Object {$_.Name -like "*foo*"}
Run Code Online (Sandbox Code Playgroud)
问题是,由于我不提前知道属性的名称,因此我不知道找到值的最佳方法。我尝试了这个:
Get-ChildItem -path hkcu:\ -recurse -erroraction silentlycontinue | get-itemproperty | where {$_.'(default)' -like "*foo*"}
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误:
get-itemproperty : Specified cast is not valid.
At line:1 char:69
+ ... u:\ -recurse -erroraction silentlycontinue | get-itemproperty | where ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ItemProperty], InvalidCastException
+ FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Run Code Online (Sandbox Code Playgroud)
即使我添加-ErrorAction SilentlyContinue到了get-itemproperty。
此外,这只能找到(default)键的值。
另外,是否可以在单个命令中搜索所有蜂箱?
我在非交互模式下运行调试器,输出写入文件.我想在执行时打印出Perl脚本的每一行,但只打印脚本本身的行.我不想看到脚本调用的库代码(File :: Basename,Exporter :: import等).这似乎应该很容易做到,但perldebug的文档只讨论限制倾销结构的深度.我想要的是什么,如果是的话,怎么样?
请注意,我正在执行我的程序,如下所示:
PERLDB_OPTS="LineInfo=temp.txt NonStop=1 AutoTrace=1 frame=2" perl -dS myprog.pl arg0 arg1
Run Code Online (Sandbox Code Playgroud) 我正在编写一个函数,旨在使当前缓冲区中的任何文件都可写,而不会被提示输入其名称或模式(我总是希望为644).我还希望自动刷新缓冲区以反映其内容现在可写的事实.
我的.emacs文件中有以下代码:
;; from http://www.stokebloke.com/wordpress/2008/04/17/emacs-refresh-f5-key/
(defun refresh-file ()
"Refresh the buffer from the disk (prompt if modified)."
(interactive)
(revert-buffer t (not (buffer-modified-p)) t))
(defun my-make-writable ()
"make file writable to owner"
(interactive)
(chmod buffer-file-name 644)
(refresh-file))
Run Code Online (Sandbox Code Playgroud)
但是,当我执行该功能时,emacs会在迷你缓冲区中显示以下错误消息:
文件名不再可读
这是相当令人不安的.但是,我仍然可以执行"chmod"命令来使文件可读和可写.
我该怎么做才能使我的功能正常工作?
因此,我试图删除行开头的一些空格,当我按下时,M-d我最终会删除比我需要的更多的内容:
(add-to-list 'load-path
"~/path-to-yasnippet")
(require 'yasnippet)
(yas-global-mode 1)
Run Code Online (Sandbox Code Playgroud)
^^ | |__ 想要删除到这里 | |___ 光标在此
我看了好几个地方,但没能做到 Vimdw命令所做的事情。
例如,Emacs 的单词操作命令似乎并不能做到这一点。