📜  Exception::getMessage 和 Exception::getLine 之间的区别

📅  最后修改于: 2022-05-13 01:56:48.317000             🧑  作者: Mango

Exception::getMessage 和 Exception::getLine 之间的区别

Exception::getMessage: PHP语言中的getMessage异常基本上是程序员用来知道异常消息的。这意味着每当代码中出现异常情况时,为了知道确切的含义以及该异常是什么,该函数都会被使用。这个函数对程序员来说非常有用,因为它可以帮助他找到异常的真实性质,并使用这些有价值的信息,他/她可以编写正确的异常处理代码。

示例:在下面的代码中, getMessage()将获取异常消息。

PHP
getMessage();
    }
?>


PHP
getLine();
    }
?>


输出
error message

Exception::getLine: PHP语言中的getLine异常基本上是程序员为了知道对应的异常发生在哪一行而使用的。这意味着每当代码中发生异常时,此特定的getLine()函数可以找出发生此异常的代码的确切位置。当我们有大量代码并且我们无法找出特定异常的位置时,此功能会有所帮助。

示例:在下面的代码中, getLine()函数将获取发生异常的行。

PHP

getLine();
    }
?>
输出
The exception has occured on line: 3

Exception::getMessage 和 Exception::getLine 之间的区别:

Exception::getMessageException::getLine
This function returns the exception message.This function returns the position of the line at which the exception has occurred.
It returns the exception message in string format.It returns the line number in integer format.
It is helpful in all types of codes.It is most helpful in huge codes ie. Codes containing many lines.