如何使用try catch处理symfony2中的错误,并像我们在C#中所做的那样将错误存储在自定义db表中。
例如
try
{
// code with exception.
}
catch(Exception ex)
{
//get the error and store information in table
}
,我担心我可能写错了php函数,或者滥用了异常。我之所以这么说,是因为如果要使用try/catch块捕获自定义异常,则使用以下函数:
public function get_specific_page($page) {
if (!is_array( $this->_page )){
throw new AisisCore_Template_TemplateException( "<div class='error'>Trying to get a property from a non array.</div>
我正在编写一个带有try-catch的PowerShell脚本,该脚本调用了一系列函数。
function A {
# exceptions here won't trigger the catch
}
function B {}
try {
# exceptions here will trigger the catch
A
B
} catch {
# handle errors
}
如何让函数在默认情况下抛出上游异常,而不是在每个函数中编写try catch块?
BEGIN TRANSACTION;
BEGIN TRY
ALTER TABLE dbo.SomeLogs
ADD SomeID NVARCHAR(250) NULL
ALTER TABLE dbo.SomeLogs
ADD SomeID NVARCHAR(250) NULL
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
DECLARE @Msg NVARCHAR(MAX);
SELECT @Msg = ERROR_MESSAGE();
RA
我想重现一部分InterruptedException行为,但我不明白它是如何工作的……
所以我有这样的代码:
public static void main(String [] args){
try{
}catch(InterruptedException ie){
}
}
当我试图编译它时,我得到了这个编译器错误
Unreachable catch block for InterruptedException. This exception is never thrown from the try statement body
我做了一个自定义异常,这并不是一个真正
我遇到了以下问题:
function upperFn(){
FetchSomeThing()
.catch(err => {
console.log(err)
})
}
function lowerFn(){
try {
upperFn()
}
catch (err){
//Here its not working anymore
console.log(err) // Catch is never used
}
}
所以我试着返回这个错误,甚至重新抛出它,但是
我正在尝试使用try/ show /catch来显示在console.log()中以正确方式格式化的错误。如果我使用这个代码:
var add = function ( a, b ) {
try {
if ( typeof a !== 'number' || typeof b !== 'number' ) throw {
name: 'TypeError!\n',
message: 'You must enter two numbers'
}
如果我有一个try/catch块来捕获IndexOutOfBounds异常,但是在相同的代码中,我想访问一个文件,那么是否可以执行一个可以捕获IOException的普通异常呢?
通常,当我使用try/catch时,我只会放入异常类型,但我以前从未尝试过。这样做是错误的,还是仅仅是错误的做法?
try {
// code to access a File which does not exist and inserts into an array index which does not exist
} catch (Exception eitherException){
//