Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

xanburzum

[Resolvido] classe de erro

Recommended Posts

Todos já precisaram de algum tratamento de erro personalizado para o seu site,uma classe que usa objeto VBScripts de manipulação de erro.

 

A classe de erro, permite-lhe exibir uma caixa de diálogo personalizada com a opção de ter uma mensagem detalhada, uma mensagem geral, e log o erro em um arquivo para consulta posterior. Ele também usa um JavaScript e DHTML para permitir que o usuário para arrastar a caixa de diálogo em torno.

 

default.asp

<%@ Language=VBScript %>
<% Option Explicit %>
<!-- #include file="includes/Classe_Erro.asp" -->
<%
'Declare nossas variáveis
Dim objError
Dim test

'Criar uma instância da classe cerror
Set objError = New CError
test = "asdf"

'Gerar um erro para que possamos ver a caixa
Response.Write(tes)

'Mostrar o erro
objError.DisplayError
Set objError = Nothing
%>

Classe_Erro.asp

<script language="JavaScript1.2">
<!--
//drag drop function for NS 4////
/////////////////////////////////
var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for IE 4+////
/////////////////////////////////

var dragapproved=false

function drag_dropie(){
if (dragapproved==true){
document.all.showimage.style.pixelLeft=tempx+event.clientX-iex
document.all.showimage.style.pixelTop=tempy+event.clientY-iey
return false
}
}

function initializedragie(){
iex=event.clientX
iey=event.clientY
tempx=showimage.style.pixelLeft
tempy=showimage.style.pixelTop
dragapproved=true
document.onmousemove=drag_dropie
}


if (document.all){
document.onmouseup=new Function("dragapproved=false")
}

////drag drop functions end here//////

function hidebox(){
if (document.all)
showimage.style.visibility="hidden"
else if (document.layers)
document.showimage.visibility="hide"
}

function showBox(){
if (document.all)
showimage.style.visibility="visible"
else if (document.layers)
document.showimage.visibility="visible"
}
//-->
</script>
<%
'----------------------------------------------------------
' Error handling class Written By Matt Rutledge, ruts@datausa.com
' Please feel free to contact me with any questions
'----------------------------------------------------------
On Error Resume Next

Class CError

'----------------------------------------------------------
' Public Declerations
'----------------------------------------------------------
Public m_bDetailedError										' Detailed Errors 0 = off , 1 = on
Public m_bLogErrors

'----------------------------------------------------------
' Private Declerations
'----------------------------------------------------------
Private m_FilePath											' File Location
Private m_LogFile											' File Name

'----------------------------------------------------------
' Private Functions
'----------------------------------------------------------
Private Sub Class_Initialize()								' Called when class is initialized
	Dim Err
	m_bDetailedError	= 1									' Turn detailed errors on
	m_bLogErrors		= 0									' Turn off logging errors
	m_FilePath			= Server.MapPath("/")				' Get Location of the Web Site
	m_LogFile			= m_FilePath & "errors.log"			' Set file location and name
End Sub

Private Sub Class_Terminate()								' Called when class terminates
	m_bDetailedError	= 0
	m_bLogErrors		= 0
End Sub
	
'----------------------------------------------------------
' Public Functions
'----------------------------------------------------------
Public Function DetailedErrors(bDetail)
	m_bDetailedError = bDetail								' Turn on/off detailed errors
End Function

Public Function LogErrors(bLog)
	m_bLogErrors = bLog										' Turn on/off error logging
End Function

Public Function LogError()
	Dim objFSO, objTextFile
	
	' Create File System Object and open Error Log for appending
	Set objFSO		= Server.CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.OpenTextFile(m_LogFile, 8, 1)
	
	' Log the Error
	objTextFile.WriteLine Date & ", " & Err.number & ", " & Err.Description 
	
	' Clean up
	objTextFile.Close
	Set objTextFile = Nothing
	Set objFSO		= Nothing
End Function

Public Function DisplayError()
	Dim m_strStandardError
	
	' Only display the error is there was one.
	If Err.number <> 0 Then
		' Set standard error message
		m_strStandardError = "An Error has occured on this page.<BR>Please contact system administrator."
		
		' Check to see if they want detailed errors
		If m_bDetailedError = 1 Then
			m_strStandardError = m_strStandardError & "<BR>Error: " & Err.number & "<BR>" & Err.Description
		End If
		
		' Check to see if were logging the error
		If m_bLogErrors = 1 Then LogError
		
		' Display the error with drag and drop capabilities
		Response.Write("<div id=""showimage"" style=""position:absolute;visibility:visible;width:260px;left:300;top:100"">" & _
		"<TABLE BORDER=""0"" BGCOLOR=""#000000"" CELLPADDING=""2"" CELLSPACING=""0"" WIDTH=""250"" ALIGN=""center"">" & _
		"<TR>" & _
		"<TD ALIGN=""left"" VALIGN=""top"" onMousedown=""initializedragie()"" onMouseover=""dragswitch=1;"" onMouseout=""dragswitch=0"" style=""cursor:hand"">" & _
		"<B STYLE=""color:#ffffff;"">Error</B>" & _
		"</TD>" & _
		"<TD ALIGN=""right"" VALIGN=""top"">" & _
		"<A HREF=""#"" onClick=""hidebox(); return false;""><IMG SRC=""images/close.gif"" BORDER=""0""></A>" & _
		"</TD>" & _
		"</TR>" & _
		"<TD ALIGN=""left"" VALIGN=""top"" COLSPAN=""2"">" & _
		"<ilayer onSelectStart=""return false;"">" & _
		"<layer onMouseover=""drag_dropns(showimage);"">" & _
		"<TABLE BORDER=""0"" BGCOLOR=""#CCCCCC"" CELLPADDING=""2"" CELLSPACING=""0"" WIDTH=""250"">" & _
			"<TR>" & _
			"<TD ALIGN=""left"" VALIGN=""top"" WIDTH=""36"">" & _
			"<BR><IMG SRC=""images/error.gif"" BORDER=""0"">" & _
			"</TD>" & _
			"<TD ALIGN=""left"" VALIGN=""top"" WIDTH=""210""><BR>" & m_strStandardError & "</TD>" & _
			"</TR>" & _
			"<TR>" & _
			"<TD ALIGN=""right"" VALIGN=""top"" COLSPAN=""2""><A HREF=""#"" onClick=""hidebox(); return false;""><IMG SRC=""images/ok.gif"" BORDER=""0""></A></TD>" & _
			"</TR>" & _
		"</TABLE>" & _
		"</layer></ilayer>" & _
		"</TD>" & _
		"</TR>" & _
		"</TABLE></div>")
	End If
End Function

End Class
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.